std::uses_allocator - cppreference.com (original) (raw)

| | | | | --------------------------------------------------------- | | ------------- | | template< class T, class Alloc > struct uses_allocator; | | (since C++11) |

If T has a nested type allocator_type which is convertible from Alloc, the member constant value is true. Otherwise value is false.

Contents

[edit] Helper variable template

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

Inherited from std::integral_constant

Member constants

| | true if T uses allocator Alloc, false otherwise (public static member constant) | | ---------------------------------------------------------------------------------- |

Member functions

| | converts the object to bool, returns value (public member function) | | ---------------------------------------------------------------------- | | | returns value (public member function) |

Member types

[edit] Uses-allocator construction

There are three conventions of passing an allocator alloc to a constructor of some type T:

[edit] Specializations

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:

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:

std::uses_allocatorstd::tuple(C++11) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::queue(C++11) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::priority\_queue(C++11) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::stack(C++11) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::flat\_map(C++23) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::flat\_set(C++23) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::flat\_multimap(C++23) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::flat\_multiset(C++23) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::function(C++11) (until C++17) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::promise(C++11) specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocatorstd::packaged\_task(C++11) (until C++17) specializes the std::uses_allocator type trait (class template specialization) [edit]

[edit] Notes

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.

[edit] See also