Skip to main content

std::allocator_traits<Alloc>::max_size

Since C++20
static constexpr size_type max_size( const Alloc& a ) noexcept;
Since C++11, Until C++20
static size_type max_size( const Alloc& a ) noexcept;

If possible, obtains the maximum theoretically possible allocation size from the allocator a, by calling a.max_size().

If the above is not possible (e.g. Alloc does not have the member function max_size() ), then returns std::numeric_limits<size_type>::max() / sizeof(value_type).

Parameters

a - allocator to detect

Return value

Theoretical maximum allocation size.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 2162C++11max_size was not requied to be noexceptrequired
LWG 2466C++11theoretical maximum allocation size in bytes was returned as fallbacksize in elements is returned

std::allocator_traits<Alloc>::max_size

Since C++20
static constexpr size_type max_size( const Alloc& a ) noexcept;
Since C++11, Until C++20
static size_type max_size( const Alloc& a ) noexcept;

If possible, obtains the maximum theoretically possible allocation size from the allocator a, by calling a.max_size().

If the above is not possible (e.g. Alloc does not have the member function max_size() ), then returns std::numeric_limits<size_type>::max() / sizeof(value_type).

Parameters

a - allocator to detect

Return value

Theoretical maximum allocation size.

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DRApplied toBehavior as publishedCorrect behavior
LWG 2162C++11max_size was not requied to be noexceptrequired
LWG 2466C++11theoretical maximum allocation size in bytes was returned as fallbacksize in elements is returned