std::allocator (3) - Linux Manuals
std::allocator: std::allocator
NAME
std::allocator - std::allocator
Synopsis
Defined in header <memory>
template< class T > (1)
struct allocator;
template<> (2) (deprecated in C++17)
struct allocator<void>; (removed in C++20)
The std::allocator class template is the default Allocator used by all standard library containers if no user-specified allocator is provided. The default allocator is stateless, that is, all instances of the given allocator are interchangeable, compare equal and can deallocate memory allocated by any other instance of the same allocator type.
The explicit specialization for void lacks the member typedefs reference, const_reference, size_type and difference_type. This specialization declares no member functions. (until C++20)
All custom allocators also must be stateless. (until C++11)
Custom allocators may contain state. Each container or another allocator-aware object stores an instance of the supplied allocator and controls allocator replacement through std::allocator_traits. (since C++11)
The default allocator satisfies allocator_completeness_requirements. (since C++17)
Member types
Type Definition
value_type T
pointer (deprecated in C++17)(removed in C++20) T*
const_pointer (deprecated in C++17)(removed in C++20) const T*
reference (deprecated in C++17)(removed in C++20) T&
const_reference (deprecated in C++17)(removed in C++20) const T&
size_type std::size_t
difference_type std::ptrdiff_t
propagate_on_container_move_assignment(C++14) std::true_type
rebind (deprecated in C++17)(removed in C++20) template< class U > struct rebind { typedef allocator<U> other; };
is_always_equal(C++17) std::true_type
Member functions
constructor (public member function)
destructor (public member function)
address obtains the address of an object, even if operator& is overloaded
(deprecated in C++17)
(removed in C++20)
allocate (public member function)
deallocate (public member function)
max_size returns the largest supported allocation size
(deprecated in C++17)
(removed in C++20)
construct constructs an object in allocated storage
(deprecated in C++17)
(removed in C++20)
destroy destructs an object in allocated storage
(deprecated in C++17)
(removed in C++20)
Non-member functions
operator== (public member function)
operator!=
Notes
The member template class rebind provides a way to obtain an allocator for a different type. For example,
std::list<T, A> allocates nodes of some internal type Node<T>, using the allocator A::rebind<Node<T>>::other (until C++11)
std::list<T, A> allocates nodes of some internal type Node<T>, using the allocator std::allocator_traits<A>::rebind_alloc<Node<T>>, which is implemented in terms of A::rebind<Node<T>>::other if A is an std::allocator (since C++11)
Example
// Run this code