std::allocator_traits
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Memory management library 
 
 
 
 
 
 
 
 
 
 
 
 
Uninitialized memory algorithms  
 
 
 
 
 
 
 
 
 
 
 
 Constrained uninitialized memory algorithms  
 
 
 
 
 
 
 
 
 
 
 
 Memory resources  
 
 
 
 
 
 
 
 
 
 
 Uninitialized storage (until C++20) 
 
 
 
 
 
 Garbage collector support (until C++23) 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(exposition only*)
allocator_traits
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
 (C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(until C++20*)
(until C++20*)
(until C++20*)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
(C++26)
std::allocator_traits
Defined in header 
 
 
<memory> 
 template< class Alloc >
struct allocator_traits;
 
 (since C++11) 
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.
It is 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.
The default, non-specialized, std::allocator_traits contains the following members:
[edit] Member types
 Type
 Definition
allocator_type
 Alloc
value_type
 Alloc::value_type
pointer
 Alloc::pointer if present, otherwise value_type*
const_pointer
 Alloc::const_pointer if present, otherwise std::pointer_traits <pointer>::rebind<const value_type>
const_void_pointer
 Alloc::const_void_pointer if present, otherwise std::pointer_traits <pointer>::rebind<const void>
difference_type
 Alloc::difference_type if present, otherwise std::pointer_traits <pointer>::difference_type
propagate_on_container_copy_assignment
 Alloc::propagate_on_container_copy_assignment if present, otherwise std::false_type 
propagate_on_container_move_assignment
 Alloc::propagate_on_container_move_assignment if present, otherwise std::false_type 
propagate_on_container_swap
 Alloc::propagate_on_container_swap if present, otherwise std::false_type 
[edit] Member alias templates
 Type
 Definition
rebind_alloc<T>
 Alloc::rebind<T>::other if present, otherwise SomeAllocator<T, Args> if this Alloc is of the form SomeAllocator<U, Args>, where Args is zero or more type arguments
rebind_traits<T>
 std::allocator_traits<rebind_alloc<T>>
[edit] Member functions
[static] (C++23)
(public static member function) [edit]
[static]
(public static member function) [edit]
 
 obtains the allocator to use after copying a standard container 
(public static member function) [edit]
(public static member function) [edit]
[edit] 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_equalprovided | 
[edit] See also
(C++11)
propagate_on_container_swap) usage(named requirement)