std::allocator_traits

定义于头文件 <memory>
template< class Alloc >
struct allocator_traits;
(C++11 起)

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

默认的非特化 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(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>>

成员函数

[静态]
用分配器分配未初始化的存储
(公开静态成员函数)
[静态]
用分配器解分配存储
(公开静态成员函数)
[静态]
在分配的存储构造对象
(函数模板)
[静态]
析构存储于分配存储的对象
(函数模板)
[静态]
返回分配器所支持的最大对象大小
(公开静态成员函数)
获得复制标准容器后使用的分配器
(公开静态成员函数)

参阅

默认的分配器
(类模板)
为多级容器实现的多级分配器
(类模板)
提供关于类指针类型的信息
(类模板)

版本历史

  • (当前 | 先前 2017年10月7日 (六) 21:17Ovenyang讨论 | 贡献 . . (3,077字节) (0). . (撤销)
  • 当前 | 先前 2017年5月29日 (一) 03:03Fruderica讨论 | 贡献. . (3,077字节) (-1,702). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:01P12bot讨论 | 贡献 . . (4,779字节) (-309). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:50P12bot讨论 | 贡献 . . (5,088字节) (+281). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:25P12讨论 | 贡献 . . (4,807字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (4,807字节) (-116). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:09P12讨论 | 贡献 . . (4,923字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (4,923字节) (+4,923). . (Translated from the English version using Google Translate)