std::allocator_traits
Defined in | memory |
template< class Alloc >
struct allocator_traits;
The allocator_traits class template provides the standardized way to access various properties of Allocators. The standard containers and other standard library components access allocators through this template, which makes it possible to use any class type as an allocator, as long as the user-provided specialization of std::allocator_traits implements all required functionality.
A program that declares an explicit or partial specialization of std::allocator_traits is ill-formed, no diagnostic required. (since C++23)The default, non-specialized, std::allocator_traits contains the following members:
Member types
pub | Type | Definition |
pub | allocator_type | Alloc |
pub | value_type | Alloc::value_type |
pub | pointer | Alloc::pointer if present, otherwise value_type* |
pub | const_pointer | Alloc::const_pointer if present, otherwise std::pointer_traits <pointer>::rebind<const value_type> |
pub | void_pointer | Alloc::void_pointer if present, otherwise std::pointer_traits <pointer>::rebind<void> |
pub | const_void_pointer | Alloc::const_void_pointer if present, otherwise std::pointer_traits <pointer>::rebind<const_void> |
pub | difference_type | Alloc::difference_type if present, otherwise std::pointer_traits <pointer>::difference_type |
pub | size_type | Alloc::size_type if present, otherwise std::make_unsigned <difference_type>::type |
pub | propagate_on_container_copy_assignment | Alloc::propagate_on_container_copy_assignment if present, otherwise std::false_type |
pub | propagate_on_container_move_assignment | Alloc::propagate_on_container_move_assignment if present, otherwise std::false_type |
pub | propagate_on_container_swap | Alloc::propagate_on_container_swap if present, otherwise std::false_type |
pub | is_always_equal | Alloc::is_always_equal if present, otherwise std::is_empty <Alloc>::type |
Member alias templates
pub | Type | Definition |
pub | rebind_alloc<T> | Alloc::rebind<T>::other if present, otherwise Alloc<T, Args> if this Alloc is Alloc<U, Args> |
pub | rebind_traits<T> | std::allocator_traits<rebind_alloc<T>> |
Member functions
pub | allocatestatic | allocates uninitialized storage using the allocator |
pub | allocate_at_least(C++23)static | allocates uninitialized storage using the allocator |
pub | deallocatestatic | deallocates storage using the allocator |
pub | constructstatic | constructs an object in the allocated storage |
pub | destroystatic | destructs an object stored in the allocated storage |
pub | max_sizestatic | returns the maximum object size supported by the allocator |
pub | select_on_container_copy_constructionstatic | obtains the allocator to use after copying a standard container |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2108 | C++11 | there was no way to show an allocator is stateless | is_always_equal provided |