|
|
Defined in header <memory> | ||
template<class T,class Alloc> struct uses_allocator; | (since C++11) | |
IfT
has a nested typeallocator_type
which is convertible fromAlloc
, the member constantvalue istrue. Otherwisevalue isfalse.
Contents |
template<class T,class Alloc> constexprbool uses_allocator_v= uses_allocator<T, Alloc>::value; | (since C++17) | |
value [static] | true ifT uses allocatorAlloc ,false otherwise(public static member constant) |
operator bool | converts the object tobool, returnsvalue (public member function) |
operator() (C++14) | returnsvalue (public member function) |
Type | Definition |
value_type | bool |
type | std::integral_constant<bool, value> |
There are three conventions of passing an allocatoralloc to a constructor of some typeT
:
T
does not use a compatible allocator (std::uses_allocator_v<T, Alloc> isfalse), thenalloc
is ignored.T
uses theleading-allocator convention (is invocable asT(std::allocator_arg, alloc, args...)), then uses-allocator construction uses this form.T
uses thetrailing-allocator convention (is invocable asT(args..., alloc)), then uses-allocator construction uses this form.std::uses_allocator
isfalse for pairs (unlike e.g.std::tuple): see pair-specific overloads ofstd::pmr::polymorphic_allocator::construct andstd::scoped_allocator_adaptor::construct(until C++20)std::uses_allocator_construction_args(since C++20).The utility functionsstd::make_obj_using_allocator, andstd::uninitialized_construct_using_allocator may be used to explicitly create an object following the above protocol, andstd::uses_allocator_construction_args can be used to prepare the argument list that matches the flavor of uses-allocator construction expected by the type. | (since C++20) |
Given aprogram-defined typeT
that does not have a nestedallocator_type
, a program can specializestd::uses_allocator
to derive fromstd::true_type forT
if any of the following requirements is satisfied:
T
has a constructor which takesstd::allocator_arg_t as the first argument, andAlloc
as the second argument.T
has a constructor which takesAlloc
as the last argument.In the above,Alloc
is a type that satisfiesAllocator or is a pointer type convertible tostd::experimental::pmr::memory_resource*(library fundamentals TS).
The following specializations are already provided by the standard library:
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
(C++11)(until C++17) | specializes thestd::uses_allocator type trait (class template specialization)[edit] |
specializes thestd::uses_allocator type trait (class template specialization)[edit] | |
(C++11)(until C++17) | specializes thestd::uses_allocator type trait (class template specialization)[edit] |
This type trait is used bystd::tuple,std::scoped_allocator_adaptor, andstd::pmr::polymorphic_allocator. It may also be used by custom allocators or wrapper types to determine whether the object or member being constructed is itself capable of using an allocator (e.g. is a container), in which case an allocator should be passed to its constructor.
(C++11) | a tag used to select allocator-aware constructors (tag)[edit] |
prepares the argument list matching the flavor of uses-allocator construction required by the given type (function template)[edit] | |
(C++20) | creates an object of the given type by means of uses-allocator construction (function template)[edit] |
creates an object of the given type at specified memory location by means of uses-allocator construction (function template)[edit] | |
(C++11) | implements multi-level allocator for multi-level containers (class template)[edit] |