C++ Standard Library C++ STL Library

C++ unordered_multimap - empty() Function



The C++ unordered_multimap::empty function is used to check whether the unordered_multimap is empty or not. It returns true if the size of the unordered_multimap is zero, else returns false.

Syntax

bool empty() const noexcept;

Parameters

No parameter is required.

Return Value

true if the size of the unordered_multimap is zero, else returns false.

Time Complexity

Constant i.e, Θ(1).

Example:

In the example below, the unordered_multimap::empty function is used to check whether the unordered_multimap is empty or not.

#include <iostream>
#include <unordered_map>
using namespace std;
 
int main (){
  unordered_multimap<string, string> uMMap;

  cout<<boolalpha;

  cout<<"Is the Unordered Multimap empty?: "<<uMMap.empty()<<"\n";

  cout<<"Add key/element pairs in the Unordered Multimap.\n";

  uMMap.insert(pair<string, string>("USA", "New York"));
  uMMap.insert(pair<string, string>("USA", "Washington"));  
  uMMap.insert(pair<string, string>("CAN", "Toronto"));

  cout<<"Now, Is the Unordered Multimap empty?: "<<uMMap.empty()<<"\n";
  return 0;
}

The output of the above code will be:

Is the Unordered Multimap empty?: true
Add key/element pairs in the Unordered Multimap.
Now, Is the Unordered Multimap empty?: false

❮ C++ <unordered_map> Library