multiset max_size() in C++ STL with Examples

The multiset::max_size() is a built-in function in C++ STL which returns the maximum number of elements a multiset container can hold.

Syntax:

multiset_name.max_size()

Parameters: The function does not accept any parameters.

Return Value: The function returns the maximum number of elements a multiset container can hold.

Below programs illustrate the above function:



Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    multiset<int> s;
  
    // Function to insert elements
    // in the multiset container
    s.insert(10);
    s.insert(13);
    s.insert(13);
    s.insert(25);
    s.insert(24);
  
    cout << "The multiset elements are: ";
    for (auto it = s.begin(); it != s.end(); it++)
        cout << *it << " ";
  
    cout << "\nThe max size of multiset: " << s.max_size();
    return 0;
}
chevron_right

Output:
The multiset elements are: 10 13 13 24 25 
The max size of multiset: 461168601842738790

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to demonstrate the
// multiset::max_size() function
// when multiset is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
  
    multiset<int> s;
  
    cout << "\nThe max size of multiset: " << s.max_size();
    return 0;
}
chevron_right

Output:
The max size of multiset: 461168601842738790

All functions of multiset

Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.





The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
C++
Practice Tags :