STD::ALLOCATOR_TRAITS(3)
π std::allocator_traits< _Alloc > π
okay bestie, so this is a page from the Library Functions Manual β yes, THE manual, capital letters and everything β and it's about std::allocator_traits< _Alloc >. Come sit with me, we're gonna make allocators make sense. π«Ά
β¨ NAME β¨
std::allocator_traits< _Alloc > β the uniform interface to all allocator types.
Like, one glow-up of an interface that every allocator can walk through. π
π SYNOPSIS π
#include <memory>
Inherited by all of these iconic little guys:
__gnu_cxx::__alloc_traits< _Char_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _CharT_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Node_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Bit_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Tp_alloc_type >,
__gnu_cxx::__alloc_traits< _Map_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Pair_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Key_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Val_alloc_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< _Node_allocator >,
__gnu_cxx::pointer< _Tp_alloc_type >,
__gnu_cxx::__alloc_traits< allocator_type >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::other< _Alloc >,
__gnu_cxx::__alloc_traits< std::allocator< value_type > >, and
__gnu_cxx::__alloc_traits< _Alloc, typename >.
not me listing twenty-something types and still being calm about it π
π Public Types π
typedef _Alloc allocator_typeβ the allocator type. the whole personality, basically.using const_pointerβ the allocator's const pointer type.using const_void_pointerβ the allocator's const void pointer type.using difference_typeβ the allocator's difference type.using is_always_equalβ whether all instances of the allocator type compare equal.using pointerβ the allocator's pointer type.using propagate_on_container_copy_assignmentβ how the allocator is propagated on copy assignment.using propagate_on_container_move_assignmentβ how the allocator is propagated on move assignment.using propagate_on_container_swapβ how the allocator is propagated on swap.template<typename _Tp> using rebind_allocβ (that's it, that's the entry, no lil description attached π« )template<typename _Tp> using rebind_traitsβ (same, no description given)using size_typeβ the allocator's size type.typedef _Alloc::value_type value_typeβ the allocated type.using void_pointerβ the allocator's void pointer type.
β Static Public Member Functions β
static constexpr pointer allocate (_Alloc &__a, size_type __n)β allocate memory.static constexpr pointer allocate (_Alloc &__a, size_type __n, const_void_pointer __hint)β allocate memory.static constexpr auto allocate_at_least (_Alloc &__a, size_type __n) -> allocation_result< pointer, size_type >β allocate memory, generously.template<typename _Tp, typename... _Args> static constexpr void construct (_Alloc &__a, _Tp *__p, _Args &&... __args) noexcept(_S_nothrow_construct< _Tp, _Args... >())β construct an object of type_Tp.static constexpr void deallocate (_Alloc &__a, pointer __p, size_type __n)β deallocate memory.template<typename _Tp> static constexpr void destroy (_Alloc &__a, _Tp *__p) noexcept(_S_nothrow_destroy< _Tp >())β destroy an object of type_Tp.static constexpr size_type max_size (const _Alloc &__a) noexceptβ the maximum supported allocation size.static constexpr _Alloc select_on_container_copy_construction (const _Alloc &__rhs)β obtain an allocator to use when copying a container.
π¦ Detailed Description π¦
template<typename _Alloc>
struct std::allocator_traits< _Alloc >
"Uniform interface to all allocator types."
Since: C++11 β¨ (an elder, but a timeless one)
πΈ Member Typedef Documentation πΈ
template<typename _Alloc> typedef _Alloc std::allocator_traits< _Alloc >::allocator_type
The allocator type.
template<typename _Alloc> using std::allocator_traits< _Alloc >::const_pointer
The allocator's const pointer type. Alloc::const_pointer if that type exists, otherwise pointer_traits<pointer>::rebind<const value_type>
template<typename _Alloc> using std::allocator_traits< _Alloc >::const_void_pointer
The allocator's const void pointer type. Alloc::const_void_pointer if that type exists, otherwise pointer_traits<pointer>::rebind<const void>
template<typename _Alloc> using std::allocator_traits< _Alloc >::difference_type
The allocator's difference type. Alloc::difference_type if that type exists, otherwise pointer_traits<pointer>::difference_type
template<typename _Alloc> using std::allocator_traits< _Alloc >::is_always_equal
Whether all instances of the allocator type compare equal. Alloc::is_always_equal if that type exists, otherwise is_empty<Alloc>::type
template<typename _Alloc> using std::allocator_traits< _Alloc >::pointer
The allocator's pointer type. Alloc::pointer if that type exists, otherwise value_type*
template<typename _Alloc> using std::allocator_traits< _Alloc >::propagate_on_container_copy_assignment
How the allocator is propagated on copy assignment. Alloc::propagate_on_container_copy_assignment if that type exists, otherwise false_type
template<typename _Alloc> using std::allocator_traits< _Alloc >::propagate_on_container_move_assignment
How the allocator is propagated on move assignment. Alloc::propagate_on_container_move_assignment if that type exists, otherwise false_type
template<typename _Alloc> using std::allocator_traits< _Alloc >::propagate_on_container_swap
How the allocator is propagated on swap. Alloc::propagate_on_container_swap if that type exists, otherwise false_type
template<typename _Alloc> using std::allocator_traits< _Alloc >::size_type
The allocator's size type. Alloc::size_type if that type exists, otherwise make_unsigned<difference_type>::type
template<typename _Alloc> typedef _Alloc::value_type std::allocator_traits< _Alloc >::value_type
The allocated type.
template<typename _Alloc> using std::allocator_traits< _Alloc >::void_pointer
The allocator's void pointer type. Alloc::void_pointer if that type exists, otherwise pointer_traits<pointer>::rebind<void>
π₯ Member Function Documentation π₯
template<typename _Alloc> constexpr pointer std::allocator_traits< _Alloc >::allocate (_Alloc & __a, size_type __n) [inline], [static], [nodiscard], [constexpr]
Allocate memory.
Parameters
__aβ an allocator.__nβ the number of objects to allocate space for.
Calls a.allocate(n)
template<typename _Alloc> constexpr pointer std::allocator_traits< _Alloc >::allocate (_Alloc & __a, size_type __n, const_void_pointer __hint) [inline], [static], [nodiscard], [constexpr]
Allocate memory.
Parameters
__aβ an allocator.__nβ the number of objects to allocate space for.__hintβ aid to locality.
Returns
Memory of suitable size and alignment for n objects of type value_type
Returns a.allocate(n, hint) if that expression is well-formed, otherwise returns a.allocate(n)
template<typename _Alloc> constexpr auto std::allocator_traits< _Alloc >::allocate_at_least (_Alloc & __a, size_type __n) -> allocation_result< pointer, size_type > [inline], [static], [nodiscard], [constexpr]
Allocate memory, generously. π (the name literally says generous, we love a self-aware king)
Parameters
__aβ an allocator.__nβ the minimum number of objects to allocate space for.
Returns
Memory of suitable size and alignment for n or more contiguous objects of type value_type.
Returns a.allocate_at_least(n) if that expression is well-formed, else { a.allocate(n), n }. When an allocator is obliged to reserve more space than required for the cited n objects, it may deliver the extra space to the caller.
template<typename _Alloc> template<typename _Tp, typename... _Args> constexpr void std::allocator_traits< _Alloc >::construct (_Alloc & __a, _Tp * __p, _Args &&... __args) [inline], [static], [constexpr], [noexcept]
Construct an object of type _Tp.
Parameters
__aβ an allocator.__pβ pointer to memory of suitable size and alignment forTp__argsβ constructor arguments.
Calls __a.construct(__p, std::forward<Args>(__args)...) if that expression is well-formed, otherwise uses placement-new to construct an object of type _Tp at location __p from the arguments __args...
template<typename _Alloc> constexpr void std::allocator_traits< _Alloc >::deallocate (_Alloc & __a, pointer __p, size_type __n) [inline], [static], [constexpr]
Deallocate memory.
Parameters
__aβ an allocator.__pβ pointer to the memory to deallocate.__nβ the number of objects space was allocated for.
Calls a.deallocate(p, n)
template<typename _Alloc> template<typename _Tp> constexpr void std::allocator_traits< _Alloc >::destroy (_Alloc & __a, _Tp * __p) [inline], [static], [constexpr], [noexcept]
Destroy an object of type _Tp.
Parameters
__aβ an allocator.__pβ pointer to the object to destroy
Calls __a.destroy(__p) if that expression is well-formed, otherwise calls __p->~_Tp()
template<typename _Alloc> constexpr size_type std::allocator_traits< _Alloc >::max_size (const _Alloc & __a) [inline], [static], [constexpr], [noexcept]
The maximum supported allocation size.
Parameters
__aβ an allocator.
Returns
__a.max_size() or numeric_limits<size_type>::max()
Returns __a.max_size() if that expression is well-formed, otherwise returns numeric_limits<size_type>::max()
template<typename _Alloc> constexpr _Alloc std::allocator_traits< _Alloc >::select_on_container_copy_construction (const _Alloc & __rhs) [inline], [static], [constexpr]
Obtain an allocator to use when copying a container.
Parameters
__rhsβ an allocator.
Returns
__rhs.select_on_container_copy_construction() or __rhs
Returns __rhs.select_on_container_copy_construction() if that expression is well-formed, otherwise returns __rhs
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
and that's the whole page bestie, we ate and left zero crumbs π β¨
this lil doc came out of the libstdc++ source, auto-generated by Doxygen, and the footer was serving std::alloc...s< _Alloc >(3) β the manual page name, no date on it, so that's all the metadata we got π π
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms