C++ Standard Library C++ STL Library

C++ <deque> - max_size() Function

The C++ deque::max_size function returns the maximum size the deque can reach. The function returns the maximum potential size the deque can reach due to known system or library implementation limitations.


size_type max_size() const;
size_type max_size() const noexcept;


No parameter is required.

Return Value

Maximum number of elements that can be held in a deque.

Time Complexity

Constant i.e, Θ(1).


In the example below, the deque::max_size function is used find out the maximum number of elements that a deque can hold.

#include <iostream>
#include <deque>
using namespace std;
int main (){
  deque<int> MyDeque{10, 20, 30, 40, 50};
  deque<int>::iterator it;

  cout<<"The deque contains:";
  for(it = MyDeque.begin(); it != MyDeque.end(); ++it)
    cout<<" "<<*it;
  cout<<"\nDeque size is: "<<MyDeque.size()<<"\n";
  cout<<"Maximum size of the Deque: "<<MyDeque.max_size()<<"\n"; 
  return 0;

A possible output could be:

The deque contains: 10 20 30 40 50
Deque size is: 5
Maximum size of the Deque: 2305843009213693951

❮ C++ <deque> Library