template< class T, class Alloc >
struct uses_allocator;
If T
has a nested type allocator_type
which is convertible from Alloc
, the member constant value is true. Otherwise value is false.
template< class T, class Alloc >
constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
T
uses allocator Alloc
, false otherwise
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.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
is false for pairs (unlike e.g. std::tuple): see pair-specific overloads of std::pmr::polymorphic_allocator::construct and std::scoped_allocator_adaptor::construct(until C++20)std::uses_allocator_construction_args(since C++20).Given a program-defined type T
that does not have a nested allocator_type
, a program can specialize std::uses_allocator
to derive from std::true_type for T
if any of the following requirements is satisfied:
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:
[edit] NotesThis 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.
[edit] See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4