std:: allocator_traits
From cppreference.net
|
定义于头文件
<memory>
|
||
|
template
<
class
Alloc
>
struct allocator_traits ; |
(C++11 起) | |
allocator_traits
类模板提供了标准化的方式来访问
分配器
的各种属性。标准容器及其他标准库组件通过此模板来访问分配器。
|
只要用户提供的
|
(C++23 前) |
|
声明
|
(C++23 起) |
默认的、非特化的
std::allocator_traits
包含以下成员:
目录 |
成员类型
| 类型 | 定义 |
allocator_type
|
Alloc
|
value_type
|
Alloc::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
|
若存在则为
Alloc::is_always_equal
,否则为
std::
is_empty
<
Alloc
>
::
type
|
成员别名模板
| 类型 | 定义 |
rebind_alloc<T>
|
若存在则为
Alloc::rebind<T>::other
,否则若此
Alloc
为
SomeAllocator
<
U, Args
>
形式,则为
SomeAllocator<T, Args>
,其中
Args
是零个或多个
类型参数
|
rebind_traits<T>
|
std :: allocator_traits < rebind_alloc < T >> |
成员函数
|
[static]
|
使用分配器分配未初始化的存储空间
(公开静态成员函数) |
|
[static]
(C++23)
|
通过分配器分配至少不小于请求大小的存储空间
(公开静态成员函数) |
|
[static]
|
使用分配器解分配存储空间
(公开静态成员函数) |
|
[static]
|
在已分配的存储空间中构造对象
(函数模板) |
|
[static]
|
销毁存储在已分配存储空间中的对象
(函数模板) |
|
[static]
|
返回分配器支持的最大对象大小
(公开静态成员函数) |
|
获取在复制标准容器后应使用的分配器
(公开静态成员函数) |
缺陷报告
下列行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时的行为 | 正确行为 |
|---|---|---|---|
| LWG 2108 | C++11 | 无法表明分配器是无状态的 |
提供
is_always_equal
|
参见
|
(C++11)
|
使用分配器的容器;关联特性(如
propagate_on_container_swap
)的用法
(命名要求) |
|
默认分配器
(类模板) |
|
|
(C++11)
|
为多层容器实现多层分配器
(类模板) |
|
(C++11)
|
提供指针类类型的信息
(类模板) |