在线文档教程
C++
应用 | Utilities

std::uses_allocator

STD::用途[医]分配器

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

如果T有一个成员类型allocator_type可转换的Alloc或者是std::experimental::erased_type%28库基础要素TS%29,成员常量valuetrue.否则valuefalse...

辅助变量模板

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

继承自STD:积分[医]常量

成员常数

value statictrue if T uses allocator Alloc, false otherwise (public static member constant)

成员函数

operator boolconverts the object to bool, returns value (public member function)
operator() (C++14)returns value (public member function)

成员类型

TypeDefinition
value_typebool
typestd::integral_constant<bool, value>

专门性

类型特征的自定义专门化std::uses_allocator对于不具有成员ty对联f的类型,则允许使用allocator_type但满足以下两项要求之一:

1%29T具有一个构造函数,该构造函数将std::allocator_arg_t作为第一个论点Alloc作为第二个论点。

2%29T具有一个构造函数,该构造函数将Alloc作为最后的论据。

在上面,Alloc是满足以下条件的类型Allocator或者是指针类型可转换为std::experimental::pmr::memory_resource*%28库基础要素TS%29。

标准库已经提供了以下专门化:

std::uses_allocator (C++11)specializes the std::uses_allocator type trait (class template specialization)
std::uses_allocator<std::variant> (C++17)specializes the std::uses_allocator type trait (class template specialization)
std::uses_allocator<std::queue> (C++11)specializes the std::uses_allocator type trait (function template)
std::uses_allocator<std::priority_queue> (C++11)specializes the std::uses_allocator type trait (function template)
std::uses_allocator<std::stack> (C++11)specializes the std::uses_allocator type trait (function template)
std::uses_allocator<std::function> (C++11) (until C++17)specializes the std::uses_allocator type trait (class template specialization)
std::uses_allocator<std::promise> (C++11)specializes the std::uses_allocator type trait (class template specialization)
std::uses_allocator<std::packaged_task> (C++11)(until C++17)specializes the std::uses_allocator type trait (class template specialization)

注记

使用此类型特征的std::scoped_allocator_adaptor,,,std::tuple,,,std::variant,和std::pmr::polymorphic_allocator它还可以被自定义分配器或包装器类型使用,以确定正在构造的对象或成员本身是否能够使用分配器%28例如。是容器%29,在这种情况下,应将分配器传递给其构造函数。

另见

allocator_arg (C++11)an object of type std::allocator_arg_t used to select allocator-aware constructors (constant)
allocator_arg_t (C++11)tag type used to select allocator-aware constructor overloads (class)
scoped_allocator_adaptor (C++11)implements multi-level allocator for multi-level containers (class template)

© cppreference.com

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

http://en.cppreference.com/w/cpp/Memory/use[医]分配器