C++ Unordered_set 库 - empty
描述
它返回一个 bool 值,指示 unordered_set 容器是否为空,即其大小是否为 0。
声明
以下是 std::unordered_set::empty 的声明。
C++11
bool empty() const noexcept;
参数
none
返回值
如果容器大小为 0,则返回 true,否则返回 false。
异常
如果任何元素比较对象抛出异常,则抛出异常。
请注意,无效的参数会导致未定义的行为。
时间复杂度
固定的时间。
示例
以下示例显示了 std::unordered_set::empty 的用法。
#include <iostream>
#include <string>
#include <unordered_set>
int main () {
std::unordered_set<std::string> first = {"sairam","krishna","mammahe"};
std::unordered_set<std::string> second;
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 not empty second is empty