C++ unordered_multiset - empty() Function
The C++ unordered_multiset::empty function is used to check whether the unordered_multiset is empty or not. It returns true if the size of the unordered_multiset is zero, else returns false.
Syntax
bool empty() const noexcept;
Parameters
No parameter is required.
Return Value
true if the size of the unordered_multiset is zero, else returns false.
Time Complexity
Constant i.e, Θ(1).
Example:
In the example below, the unordered_multiset::empty function is used to check whether the unordered_multiset is empty or not.
#include <iostream> #include <unordered_set> using namespace std; int main (){ unordered_multiset<int> uMSet; cout<<boolalpha; cout<<"Is the Unordered Multiset empty?: "<<uMSet.empty()<<"\n"; cout<<"Add elements in the Unordered Multiset.\n"; uMSet.insert(10); uMSet.insert(20); uMSet.insert(30); cout<<"Now, Is the Unordered Multiset empty?: "<<uMSet.empty()<<"\n"; return 0; }
The output of the above code will be:
Is the Unordered Multiset empty?: true Add elements in the Unordered Multiset. Now, Is the Unordered Multiset empty?: false
❮ C++ <unordered_set> Library