cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : list : max_size
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
list
comparison operators
list::list
list::~list
member functions:
· list::assign
· list::back
· list::begin
· list::clear
· list::empty
· list::end
· list::erase
· list::front
· list::get_allocator
· list::insert
· list::max_size
· list::merge
· list::operator=
· list::pop_back
· list::pop_front
· list::push_back
· list::push_front
· list::rbegin
· list::remove
· list::remove_if
· list::rend
· list::resize
· list::reverse
· list::size
· list::sort
· list::splice
· list::swap
· list::unique

-

list::max_size public member function
size_type max_size () const;

Return maximum size

Returns the maximum number of elements that the list container 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 list container can have as its content.

Member type size_type is an unsigned integral type.

Example

// list::max_size
#include <iostream>
#include <list>
using namespace std;

int main ()
{
  unsigned int i;
  list<int> mylist;

  cout << "Enter number of elements: ";
  cin >> i;

  if (i<mylist.max_size()) mylist.resize(i);
  else cout << "That size exceeds the limit.\n";

  return 0;
}

Here, member max_size is used to check beforehand whether the requested size will be allowed by member resize.

Complexity

Constant.

See also

list::size Return size (public member function)
list::resize Change size (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us