...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::container::allocator_traits
// In header: <boost/container/allocator_traits.hpp> template<typename Alloc> struct allocator_traits { // types typedef Alloc allocator_type; typedef Alloc::value_type value_type; typedef unspecified pointer; typedef see_documentation const_pointer; typedef see_documentation reference; typedef see_documentation const_reference; typedef see_documentation void_pointer; typedef see_documentation const_void_pointer; typedef see_documentation difference_type; typedef see_documentation size_type; typedef see_documentation propagate_on_container_copy_assignment; typedef see_documentation propagate_on_container_move_assignment; typedef see_documentation propagate_on_container_swap; typedef see_documentation rebind_alloc; typedef allocator_traits< rebind_alloc< T > > rebind_traits; // member classes/structs/unions template<typename T> struct portable_rebind_alloc { // types typedef see_documentation type; }; // public static functions static pointer allocate(Alloc &, size_type); static void deallocate(Alloc &, pointer, size_type); static pointer allocate(Alloc &, size_type, const_void_pointer); template<typename T> static void destroy(Alloc &, T *) noexcept; static size_type max_size(const Alloc &) noexcept; static Alloc select_on_container_copy_construction(const Alloc &); template<typename T, class... Args> static void construct(Alloc &, T *, Args &&...); };
The class template allocator_traits supplies a uniform interface to all allocator types. This class is a C++03-compatible implementation of std::allocator_traits
allocator_traits
public
typesAlloc::pointer if such a type exists; otherwise, value_type*
typedef see_documentation const_pointer;
Alloc::const_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<const
typedef see_documentation reference;
Non-standard extension Alloc::reference if such a type exists; otherwise, value_type&
typedef see_documentation const_reference;
Non-standard extension Alloc::const_reference if such a type exists ; otherwise, const value_type&
typedef see_documentation void_pointer;
Alloc::void_pointer if such a type exists ; otherwise, pointer_traits<pointer>::rebind<void>.
typedef see_documentation const_void_pointer;
Alloc::const_void_pointer if such a type exists ; otherwis e, pointer_traits<pointer>::rebind<const
typedef see_documentation difference_type;
Alloc::difference_type if such a type exists ; otherwise, pointer_traits<pointer>::difference_type.
typedef see_documentation size_type;
Alloc::size_type if such a type exists ; otherwise, make_unsigned<difference_type>::type
typedef see_documentation propagate_on_container_copy_assignment;
Alloc::propagate_on_container_copy_assignment if such a type exists, otherwise an integral_constant type with internal constant static member value
== false.
typedef see_documentation propagate_on_container_move_assignment;
Alloc::propagate_on_container_move_assignment if such a type exists, otherwise an integral_constant type with internal constant static member value
== false.
typedef see_documentation propagate_on_container_swap;
Alloc::propagate_on_container_swap if such a type exists, otherwise an integral_constant type with internal constant static member value
== false.
typedef see_documentation rebind_alloc;
Defines an allocator: Alloc::rebind<T>::other if such a type exists; otherwise, Alloc<T, Args> if Alloc is a class template instantiation of the form Alloc<U, Args>, where Args is zero or more type arguments ; otherwise, the instantiation of rebind_alloc is ill-formed.
In C++03 compilers rebind_alloc
is a struct derived from an allocator deduced by previously detailed rules.
typedef allocator_traits< rebind_alloc< T > > rebind_traits;
In C++03 compilers rebind_traits
is a struct derived from allocator_traits<OtherAlloc>
, where OtherAlloc
is the allocator deduced by rules explained in rebind_alloc
.
allocator_traits
public static functionsstatic pointer allocate(Alloc & a, size_type n);
Returns: a.allocate(n)
static void deallocate(Alloc & a, pointer p, size_type n);
Returns: a.deallocate(p, n)
Throws: Nothing
static pointer allocate(Alloc & a, size_type n, const_void_pointer p);
Effects: calls a.allocate(n, p)
if that call is well-formed; otherwise, invokes a.allocate(n)
template<typename T> static void destroy(Alloc & a, T * p) noexcept;
Effects: calls a.destroy(p)
if that call is well-formed; otherwise, invokes p->~T()
.
static size_type max_size(const Alloc & a) noexcept;
Returns: a.max_size()
if that expression is well-formed; otherwise, numeric_limits<size_type>::max()
.
static Alloc select_on_container_copy_construction(const Alloc & a);
Returns: a.select_on_container_copy_construction()
if that expression is well-formed; otherwise, a.
template<typename T, class... Args> static void construct(Alloc & a, T * p, Args &&... args);
Effects: calls a.construct(p, std::forward<Args>(args)...)
if that call is well-formed; otherwise, invokes ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...)