public member function
<set>

std::multiset::max_size

size_type max_size() const;
size_type max_size() const noexcept;
Return maximum size
Returns the maximum number of elements that the multiset container can hold.

This is the maximum potential size the container can reach due to known system or library implementation limitations, but the container is by no means guaranteed to be able to reach that size: it can still fail to allocate storage at any point before that size is reached.

Parameters

none

Return Value

The maximum number of elements a multiset container can hold as content.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// multiset::max_size
#include <iostream>
#include <set>

int main ()
{
  std::multiset<int> mymultiset;

  if (mymultiset.max_size()>1000)
  {
    for (int i=0; i<1000; i++) mymultiset.insert(i);
    std::cout << "The multiset contains 1000 elements.\n";
  }
  else std::cout << "The multiset could not hold 1000 elements.\n";

  return 0;
}


Complexity

Constant.

Iterator validity

No changes.

Data races

The container is accessed.
Concurrently accessing the elements of a multiset is safe.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also