Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
set
comparison operators
set::set
set::~set
member functions:
set::begin
set::clear
set::count
set::empty
set::end
set::equal_range
set::erase
set::find
set::get_allocator
set::insert
set::key_comp
set::lower_bound
set::max_size
set::operator=
set::rbegin
set::rend
set::size
set::swap
set::upper_bound
set::value_comp


set::max_size

public member function
size_type max_size () const;

Return maximum size

Returns the maximum number of elements that the set container object can hold.

This is the maximum potential size the container can reach due to system or library implementation limitations.

Parameters

none

Return Value

The maximum number of elements a set container can have as its 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
18
19
// set::max_size
#include <iostream>
#include <set>
using namespace std;
int main ()
{
  int i;
  set<int> myset;
  if (myset.max_size()>1000)
  {
    for (i=0; i<1000; i++) myset.insert(i);
    cout << "The set contains 1000 elements.\n";
  }
  else cout << "The set could not hold 1000 elements.\n";
  return 0;
}


Here, member max_size is used to check beforehand whether the set will allow for 1000 elements to be inserted.

Complexity

Constant.

See also