It returns a bool value indicating whether the unordered_set container is empty, i.e. whether its size is 0.
Following is the declaration for std::unordered_set::empty.
bool empty() const noexcept;
none
It returns true if the container size is 0, false otherwise.
Exception is thrown if any element comparison object throws exception.
Please note that invalid arguments cause undefined behavior.
constant time.
The following example shows the usage of 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; }
Let us compile and run the above program, this will produce the following result −
first is not empty second is empty