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
map
comparison operators
map::map
map::~map
member functions:
map::begin
map::clear
map::count
map::empty
map::end
map::equal_range
map::erase
map::find
map::get_allocator
map::insert
map::key_comp
map::lower_bound
map::max_size
map::operator=
map::operator[]
map::rbegin
map::rend
map::size
map::swap
map::upper_bound
map::value_comp


map::max_size

public member function
size_type max_size () const;

Return maximum size

Returns the maximum number of elements that the map 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 map 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
// map::max_size
#include <iostream>
#include <map>
using namespace std;
int main ()
{
  int i;
  map<int,int> mymap;
  if (mymap.max_size()>1000)
  {
    for (i=0; i<1000; i++) mymap[i]=0;
    cout << "The map contains 1000 elements.\n";
  }
  else cout << "The map could not hold 1000 elements.\n";
  return 0;
}


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

Complexity

Constant.

See also