目录

empty

描述 (Description)

它返回一个bool值,指示unordered_set容器是否为空,即其大小是否为0。

声明 (Declaration)

以下是std :: unordered_set :: empty的声明。

C++11

bool empty() const noexcept;

参数 (Parameters)

没有

返回值

如果容器大小为0,则返回true,否则返回false。

异常 (Exceptions)

如果任何元素比较对象抛出异常,则抛出异常。

请注意,无效参数会导致未定义的行为。

时间复杂

恒定时间。

例子 (Example)

以下示例显示了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
↑回到顶部↑
WIKI教程 @2018