C++ multiset - max_size() Function
The C++ multiset::max_size function returns 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.
Syntax
size_type max_size() const;
size_type max_size() const noexcept;
Parameters
No parameter is required.
Return Value
Maximum number of elements that can be held in a multiset.
Time Complexity
Constant i.e, Θ(1).
Example:
In the example below, 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: 230584300921369395
❮ C++ <set> Library