std::uses_allocator

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

T 拥有:1)内嵌定义类型 allocator_type ,并且该类型能从 Alloc 转换,2)或者该类型是 std::experimental::erased_type 的别名 (库基础 TS),则成员常量 valuetrue 。否则 valuefalse

目录

辅助变量模板

template< class T, class Alloc >
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
(C++17 起)

继承自 std::integral_constant

成员常量

value
[静态]
T 使用分配器 Alloc则为 true ,否则为 false
(公开静态成员常量)

成员函数

operator bool
转换对象为 bool ,返回 value
(公开成员函数)
operator()
(C++14)
返回 value
(公开成员函数)

成员类型

类型 定义
value_type bool
type std::integral_constant<bool, value>

特化

类型特性 std::uses_allocator 的自定义特化对无成员 typedef allocator_type 的类型允许,但必须满足下列二个要求之一:

1) T 拥有接收 std::allocator_arg_t 为首参数, Alloc 为第二参数的构造函数。
2) T 拥有接收 Alloc 为最后参数的构造函数。

上述情况中, Alloc 是满足分配器 (Allocator) 要求的类型,或是可转换到 std::experimental::pmr::memory_resource* 的指针类型 (库基础 TS)

标准库已提供下列特化:

特化 std::uses_allocator 类型特性
(类模板特化)
特化 std::uses_allocator 类型特性
(函数模板)
特化 std::uses_allocator 类型特性
(函数模板)
特化 std::uses_allocator 类型特性
(函数模板)
特化 std::uses_allocator 类型特性
(类模板特化)
特化 std::uses_allocator 类型特性
(类模板特化)
特化 std::uses_allocator 类型特性
(类模板特化)

注意

此类型特性为 std::scoped_allocator_adaptorstd::tuplestd::variantstd::pmr::polymorphic_allocator 所用。它亦可为自定义分配器或封装类型所用,以确定要构造的对象或成员是否足以使用分配器(例如是容器的情况),该情况下应传递给其构造函数分配器。

参阅

用于选择具分配器的构造函数的 std::allocator_arg_t 对象
(常量)
标签类型,用于选择分配器感知的构造函数重载
(类)
为多级容器实现的多级分配器
(类模板)

版本历史

  • (当前 | 先前 2017年10月15日 (日) 17:25118.112.207.148讨论. . (2,359字节) (+47). . (撤销)
  • 当前 | 先前 2017年8月28日 (一) 00:34Fruderica讨论 | 贡献 . . (2,312字节) (-53). . (delete for variant) (撤销)
  • 当前 | 先前 2017年5月29日 (一) 03:50Fruderica讨论 | 贡献. . (2,365字节) (-655). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:08P12bot讨论 | 贡献 . . (3,020字节) (-208). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 13:54P12bot讨论 | 贡献 . . (3,228字节) (+265). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:45P12讨论 | 贡献 . . (2,963字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,963字节) (-44). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:56P12讨论 | 贡献 . . (3,007字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (3,007字节) (+3,007). . (Translated from the English version using Google Translate)