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

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

Note: Multiset is an ordered data container which implies all its elements are ordered all the time.


size_type max_size() const;
size_type max_size() const noexcept;


No parameter is required.

Return Value

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

Time Complexity

Constant i.e, Θ(1).


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

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

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

  cout<<"\nMultiset size is: "<<MyMSet.size()<<"\n";
  cout<<"Maximum size of the Multiset: "<<MyMSet.max_size()<<"\n"; 
  return 0;

A possible output could be:

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

❮ C++ <set> Library