C++ unordered_set empty() Function
Example
Check if two unordered sets are empty:
unordered_set<string> cars = {"Volvo", "BMW", "Ford", "Mazda"};
unordered_set<string> fruits;
cout << cars.empty() << "\n";
cout << fruits.empty();
Definition and Usage
The empty() function checks whether an unordered set is empty or not.
It returns 1 (true) if the unordered set has no elements, and 0 (false) if it has one or more elements.
The empty function is defined in the <unordered_set> header file.
Syntax
unordered_set.empty()
Parameter Values
None.
Technical Details
| Returns: | A boolean value: true (1) if the unordered set is empty, and false (0) if it is not. |
|---|
Related Pages
Read more about unordered sets in our Unordered Set Tutorial.