Defined in header <memory> | ||
---|---|---|
template< class T, class Alloc > struct uses_allocator; | (since C++11) |
If T
has a member typedef allocator_type
which is convertible from Alloc
or is an alias of std::experimental::erased_type
(library fundamentals TS), the member constant value
is true
. Otherwise value
is false
.
template< class T, class Alloc > inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; | (since C++17) |
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> |
There are three conventions of passing an allocator alloc
to a constructor of some type T
:
T
does not use a compatible allocator (std::uses_allocator_v<T, Alloc>
is false), then alloc
is ignored. std::uses_allocator_v<T, Alloc>
is true, and T
uses the leading-allocator convention (is invocable as T(std::allocator_arg, alloc, args...)
), then uses-allocator construction uses this form T
uses the trailing-allocator convention (is invocable as T(args..., alloc)
), then uses-allocator construction uses this form std::uses_allocator_v<T, Alloc>
is true, but the type does not follow either of the two allowed conventions) std::pair
is treated as a uses-allocator type even though std::uses_allocator
is false for pairs (unlike e.g. std::tuple
): see pair-specific overloads of std::polymoprhic_allocator::construct
and std::scoped_allocator_adaptor::construct
(until C++20)std::uses_allocator_construction_args
(since C++20) The utility functions | (since C++20) |
Custom specializations of the type trait std::uses_allocator
are allowed for types that do not have the member typedef allocator_type
but satisfy one of the following two requirements:
T
has a constructor which takes std::allocator_arg_t
as the first argument, and Alloc
as the second argument.T
has a constructor which takes Alloc
as the last argument.In the above, Alloc
is a type that satisfies Allocator or is a pointer type convertible to std::experimental::pmr::memory_resource*
(library fundamentals TS).
The following specializations are already provided by the standard library:
(C++11) | specializes the std::uses_allocator type trait (class template specialization) |
(C++11) | specializes the std::uses_allocator type trait (function template) |
(C++11) | specializes the std::uses_allocator type trait (function template) |
(C++11) | specializes the std::uses_allocator type trait (function template) |
(C++11) (until C++17) | specializes the std::uses_allocator type trait (class template specialization) |
(C++11) | specializes the std::uses_allocator type trait (class template specialization) |
(C++11)(until C++17) | specializes the std::uses_allocator type trait (class template specialization) |
This type trait is used by std::tuple
, std::scoped_allocator_adaptor
, and std::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) | an object of type std::allocator_arg_t used to select allocator-aware constructors (constant) |
(C++11) | tag type used to select allocator-aware constructor overloads (class) |
(C++20) | prepares the argument list matching the flavor of uses-allocator construction required by the given type (function template) |
(C++20) | creates an object of the given type by means of uses-allocator construction (function template) |
(C++20) | creates an object of the given type at specified memory location by means of uses-allocator construction (function template) |
(C++11) | implements multi-level allocator for multi-level containers (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/memory/uses_allocator