C++ unordered_map empty() Function
Example
Check if two unordered maps are empty:
unordered_map<string, int> people = {{"John", 32}, {"Adele", 45}, {"Bo", 29}};
unordered_map<string, int> students;
cout << people.empty() << "\n";
cout << students.empty();
Definition and Usage
The empty() function checks whether an unordered map is empty or not.
It returns 1 (true) if the unordered map has no elements, and 0 (false) if it has one or more elements.
The empty function is defined in the <unordered_map> header file.
Syntax
unordered_map.empty()
Parameter Values
None.
Technical Details
| Returns: | A boolean value: true (1) if the unordered map is empty, and false (0) if it is not. |
|---|
Related Pages
Read more about unordered maps in our Unordered Map Tutorial.