Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library

The C++ unordered_multimap::max_size function is used to return the maximum size the unordered_multimap can reach. The function returns the maximum potential size the unordered_multimap can reach due to known system or library implementation limitations.


size_type max_size() const noexcept;


No parameter is required.

Return Value

Maximum number of elements that can be held in a unordered_multimap.

Time Complexity

Constant i.e, Θ(1).


In the below example, the unordered_multimap::max_size function is used find out the maximum number of elements that a unordered_multimap can hold.

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

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

  cout<<"The unordered_multimap contains:\n";
  for(it = uMMap.begin(); it != uMMap.end(); ++it)
     cout<<it->first<<"  "<<it->second<<"\n";
  cout<<"\nUnordered Multimap size is: "<<uMMap.size()<<"\n";
  cout<<"Maximum size of the Unordered Multimap: "<<uMMap.max_size()<<"\n"; 
  return 0;

A possible output could be:

The unordered_multimap contains:
CAN  Montreal
CAN  Toronto
IND  Delhi
USA  Washington
USA  New York

Unordered Multimap size is: 5
Maximum size of the Unordered Multimap: 576460752303423487

❮ C++ - Unordered Multimap