提供关于分配器类型的信息

 

std::allocator_traits

template< class Alloc >
struct allocator_traits;

(C++11 起)

allocator_traits 类模板提供访问分配器 (Allocator) 各种属性的标准化方式。标准容器和其他标准库组件通过此模板访问分配器,这使得能以任何类类型为分配器,只要用户提供的 allocator_traits 特化实现所有要求的功能。

默认的非特化 allocator_traits 含有下列成员:

成员类型

类型定义
allocator_typeAlloc
value_typeAlloc::value_type
pointer若存在则为 Alloc::pointer ,否则为 value_type*
const_pointer若存在则为 Alloc::const_pointer ,否则为 std::pointer_traits<pointer>::rebind<const value_type>
void_pointer若存在则为 Alloc::void_pointer ,否则为 std::pointer_traits<pointer>::rebind<void>
const_void_pointer若存在则为 Alloc::const_void_pointer ,否则为 std::pointer_traits<pointer>::rebind<const void>
difference_type若存在则为 Alloc::difference_type ,否则为 std::pointer_traits<pointer>::difference_type
size_type若存在则为 Alloc::size_type ,否则为 std::make_unsigned<difference_type>::type
propagate_on_container_copy_assignment若存在则为 Alloc::propagate_on_container_copy_assignment ,否则为 std::false_type
propagate_on_container_move_assignment若存在则为 Alloc::propagate_on_container_move_assignment ,否则为 std::false_type
propagate_on_container_swap若存在则为 Alloc::propagate_on_container_swap ,否则为 std::false_type
is_always_equal(C++17 起)若存在则为 Alloc::is_always_equal ,否则为 std::is_empty<Alloc>::type

 

成员别名模版

类型定义
rebind_alloc<T>若存在则为 Alloc::rebind<T>::other ,否则若 Alloc<T, Args> 则为 Alloc<U, Args>
rebind_traits<T>std::allocator_traits<rebind_alloc<T>>

成员函数

allocate

[静态]

用分配器分配未初始化的存储
(公开静态成员函数)

deallocate

[静态]

用分配器解分配存储
(公开静态成员函数)

construct

[静态]

在分配的存储构造对象
(函数模板)

destroy

[静态]

析构存储于已分配存储的对象
(函数模板)

max_size

[静态]

返回分配器所支持的最大对象大小
(公开静态成员函数)

select_on_container_copy_construction

[静态]

获得复制标准容器后使用的分配器
(公开静态成员函数)

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐