std::multimap<Key,T,Compare,Allocator>::empty
来自cppreference.com
bool empty() const; |
(C++11 起为 noexcept) (C++26 起为 constexpr) |
|
检查容器是否无元素。
目录 |
[编辑] 返回值
容器为空时返回 true,否则返回 false。
[编辑] 复杂度
常数。
[编辑] 示例
下列代码用 empty
检查 std::multimap<int, int> 是否含有任何元素:
运行此代码
#include <iostream> #include <map> #include <utility> int main() { std::multimap<int,int> numbers; std::cout << std::boolalpha; std::cout << "起初, numbers.empty(): " << numbers.empty() << '\n'; numbers.emplace(42, 13); numbers.insert(std::make_pair(13317, 123)); std::cout << "添加元素后, numbers.empty(): " << numbers.empty() << '\n'; }
输出:
起初, numbers.empty(): true 添加元素后, numbers.empty(): false
[编辑] 参阅
返回元素数 (公开成员函数) | |
(C++17) |
检查容器是否为空 (函数模板) |