std::unordered_multiset<Key,Hash,KeyEqual,Allocator>::empty

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

检查容器是否无元素。

目录

[编辑] 返回值

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

[编辑] 复杂度

常数。

[编辑] 示例

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

#include <iostream>
#include <unordered_set>
 
int main()
{
    std::unordered_multiset<int> numbers;
    std::cout << std::boolalpha;
    std::cout << "起初, numbers.empty(): " << numbers.empty() << '\n';
 
    numbers.insert(42);
    numbers.insert(19937);
    std::cout << "添加元素后, numbers.empty(): " << numbers.empty() << '\n';
}

输出:

起初,numbers.empty(): true
添加元素后, numbers.empty(): false

[编辑] 参阅

返回元素数
(公开成员函数) [编辑]
(C++17)
检查容器是否为空
(函数模板) [编辑]