unordered_map empty in C++ STL
unordered_map::empty() function is used to check whether container size is zero or not. If container size is zero then it return TRUE otherwise it return FALSE.
Syntax:
unordered_map_name.empty()
Parameters: This function does not accept any parameter
Return type: This function returns boolean value TRUE or FALSE.
Examples:
Input: ump = { {1, 2}, {3, 4}, {5, 6}, {7, 8}}
ump.empty();
Output: FalseInput: ump = { };
ump.empty();
Output: True
// CPP program to illustrate // Implementation of unordered_map empty() function #include <bits/stdc++.h> using namespace std; int main() { // Take any two unordered_map unordered_map<int, int> ump1, ump2; // Inserting values ump1[1] = 2; ump1[3] = 4; ump1[5] = 6; ump1[7] = 8; // Print the size of container cout << "ump1 size = " << ump1.size() << endl; cout << "ump2 size = " << ump2.size() << endl; // Running the function for ump1 if (ump1.empty()) cout << "True\n"; else cout << "False\n"; // Running the function for ump2 if (ump2.empty()) cout << "True\n"; else cout << "False\n"; // Running the function for ump1 after // clearing it ump1.clear(); if (ump1.empty()) cout << "True\n"; else cout << "False\n"; return 0; } |
ump1 size = 4 ump2 size = 0 False True True
Recommended Posts:
- map::empty() in C++ STL
- set::empty() in C++ STL
- array::empty() in C++ STL
- match_results empty() in C++ STL
- multimap empty() function in C++ STL
- Best way to initialize empty array in PHP
- list empty() function in C++ STL
- multiset empty() function in C++ STL
- unordered_multiset empty() function in C++STL
- How to check whether an array is empty using PHP?
- unordered_multimap empty() function in C++ STL
- unordered_set empty() function in C++ STL
- Why is the size of an empty class not zero in C++?
- Why to check both isset() and !empty() function in PHP ?
- How to check an object is empty using JavaScript?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



