In C++, std::deque::max_size() returns the largest number of elements that a std::deque could theoretically hold. The limit comes from the element type and the library, not from your free memory.
The number is usually huge. Real programs run out of memory long before they reach it. Include <deque> to use it.
This is a member of std::deque<T>, a double-ended queue. A deque is fast at adding and removing at both ends, and it allows access by index like std::vector. Unlike a vector, its elements are stored in several blocks, not in one contiguous block.
Syntax
Call max_size with empty brackets. It takes no arguments.
C++
std::size_t limit = d.max_size();
Call
What it does
d.max_size()
Returns the largest possible element count for this deque type.
size() tells you how many elements the deque holds now. max_size() is only an upper limit.
Library declarations
C++
size_type max_size() const noexcept;
Parameters
Parameter
Description
None
max_size() takes no parameters. Call it with empty brackets.
Return Value
Return Value
Description
size_type
The theoretical maximum number of elements. The exact value depends on the compiler, the system, and the element type.
C++ Examples
Example 1 — Basic max_size()
The exact number differs per computer, so the example checks simple facts instead.