std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator>::empty

来自cppreference.com
 
 
 
 
bool empty()constnoexcept;
(C++11 起)
(C++26 起为 constexpr)

检查容器是否无元素。

目录

[编辑]返回值

容器为空时返回 true,否则返回 false

[编辑]复杂度

常数。

[编辑]示例

下列代码用 empty 检查 std::unordered_multimap<int, int> 是否含有任何元素:

#include <iostream>#include <unordered_map>#include <utility>   int main(){std::unordered_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)
检查容器是否为空
(函数模板)[编辑]
close