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


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

Syntax

size_type max_size() const noexcept;

Parameters

No parameter is required.

Return Value

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

Time Complexity

Constant i.e, Θ(1).

Example:

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

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet{55, 25, 128, 5, 72};
  unordered_multiset<int>::iterator it;

  cout<<"The Unordered Multiset contains:";
  for(it = uMSet.begin(); it != uMSet.end(); ++it)
    cout<<" "<<*it;

  cout<<"\nUnordered Multiset size is: "<<uMSet.size()<<"\n";
  cout<<"Maximum size of the Unordered Multiset: "<<uMSet.max_size()<<"\n"; 
  
  return 0;
}

A possible output could be:

The Unordered Multiset contains: 5 72 128 25 55
Unordered Multiset size is: 5
Maximum size of the Unordered Multiset: 1152921504606846975

❮ C++ <unordered_set> Library