在线文档教程
C++
动态内存管理 | Dynamic memory management

std::allocator_traits

STD::分配器[医]性状

Defined in header
template< class Alloc > struct allocator_traits;(since C++11)

allocator_traits类模板提供了标准的方法来访问Allocator斯标准容器和其他标准库组件通过此模板访问分配器,这使得可以使用任何类类型作为分配器,只要用户提供的专门化allocator_traits实现所有必需的功能。

默认的,非专门化的,allocator_traits包含下列成员:

成员类型

TypeDefinition
allocator_typeAlloc
value_typeAlloc::value_type
pointerAlloc::pointer if present, otherwise value_type*
const_pointerAlloc::const_pointer if present, otherwise std::pointer_traits<pointer>::rebind<const value_type>
void_pointerAlloc::void_pointer if present, otherwise std::pointer_traits<pointer>::rebind<void>
const_void_pointerAlloc::const_void_pointer if present, otherwise std::pointer_traits<pointer>::rebind<const void>
difference_typeAlloc::difference_type if present, otherwise std::pointer_traits<pointer>::difference_type
size_typeAlloc::size_type if present, otherwise std::make_unsigned<difference_type>::type
propagate_on_container_copy_assignmentAlloc::propagate_on_container_copy_assignment if present, otherwise std::false_type
propagate_on_container_move_assignmentAlloc::propagate_on_container_move_assignment if present, otherwise std::false_type
propagate_on_container_swapAlloc::propagate_on_container_swap if present, otherwise std::false_type
is_always_equal(since C++17)Alloc::is_always_equal if present, otherwise std::is_empty<Alloc>::type

成员别名模板

TypeDefinition
rebind_alloc<T>Alloc::rebind<T>::other if present, otherwise Alloc<T, Args> if this Alloc is Alloc<U, Args>
rebind_traits<T>std::allocator_traits<rebind_alloc<T>>

成员函数

allocate staticallocates uninitialized storage using the allocator (public static member function)
deallocate staticdeallocates storage using the allocator (public static member function)
construct staticconstructs an object in the allocated storage (function template)
destroy staticdestructs an object stored in the allocated storage (function template)
max_size staticreturns the maximum object size supported by the allocator (public static member function)
select_on_container_copy_construction staticobtains the allocator to use after copying a standard container (public static member function)

另见

allocatorthe default allocator (class template)
scoped_allocator_adaptor (C++11)implements multi-level allocator for multi-level containers (class template)
pointer_traits (C++11)provides information about pointer-like types (class template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/Memory/allocator[医]性状