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库基础要素T
S%29,成员常量value
是true
.否则value
是false
...
辅助变量模板
template< class T, class Alloc > inline constexpr bool uses_allocator_v = uses_allocator | | (since C++17) |
---|
继承自STD:积分[医]常量
成员常数
value static | true if T uses allocator Alloc, false otherwise (public static member constant) |
---|
成员函数
operator bool | converts the object to bool, returns value (public member function) |
---|---|
operator() (C++14) | returns value (public member function) |
成员类型
Type | Definition |
---|---|
value_type | bool |
type | std::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 | 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。