Skip to content
Related Articles

Related Articles

multiset max_size() in C++ STL
  • Last Updated : 06 Sep, 2019

The multiset::max_size() is an observer function in C++ STL which returns the maximum number of elements a container can hold. This limit might be due to system or library implementations. Being an observer function it does not modify the multiset in any way.

Syntax:

multiset_name.max_size()

Parameters: This function does not accept any parameters.

Return Value: This method returns a positive integer denoting the maximum number of elements the container can hold.

Note: The value returned by this function is usually the theoretical limit of the size of the container. However, at runtime, the size of the container may be limited to a value less than that returned by max_size() function due to RAM limitations.

The program below demonstrates the use of unordered_multiset::max_size()




// C++ program to demonstrate the use of
// multiset max_size()
  
#include <iostream>
#include <unordered_set>
  
using namespace std;
  
int main()
{
    // declaring unordered multiset gfg
    unordered_multiset<int> gfg;
    unsigned int max_elements;
  
    // calculating the max size of multiset gfg
    max_elements = gfg.max_size();
  
    cout << "Number of elements "
         << "the multiset can hold is: "
         << max_elements << endl;
    return 0;
}
Output:
Number of elements the multiset can hold is: 4294967295
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :