std::
unordered_set::empty
公众成员函数 <unordered_set>
bool empty() const noexcept;
|
测试容器是否为空
返回unordered_set容器是否为空(即其大小是否为0)。
这个函数不会以任何方式修改容器。要清除集合容器的内容,请参见unordered_set::clear。
☲ 参数
-
none
☉ 返回值
如果容器大小为0则为True,否则为false。
☣ 示例
// unordered_set::empty
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_set<std::string> first;
std::unordered_set<std::string> second = {"alpha","beta","gamma"};
std::cout << "first " << (first.empty() ? "is empty" : "is not empty" ) << std::endl;
std::cout << "second " << (second.empty() ? "is empty" : "is not empty" ) << std::endl;
return 0;
}
|
输出:
first is empty
second is not empty
✥ 复杂度
常量
☣ 迭代器的有效性
不变
🍄 另请参阅
unordered_set::clear |
清除内容(公众成员函数) |
unordered_set::size |
返回元素个数(公众成员函数) |