std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::empty
来自cppreference.com
<tbody>
</tbody>
bool empty() const noexcept; |
(C++23 起) | |
检查底层容器是否为空,即是否 c.empty()。
检查底层各容器是否没有元素。等价于:return begin() == end();。
参数
(无)
返回值
若底层各容器为空则为 true,否则为 false。
复杂度
常数。
示例
下列代码用 empty 检查 std::flat_multimap<int, int> 是否含有任何元素:
运行此代码
#include <iostream>
#include <flat_map>
#include <utility>
int main()
{
std::flat_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) |
检查容器是否为空 (函数模板) |