std::uses_allocator - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::uses_allocator

From cppreference.com
< cpp‎ | memory

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`, provides the member constant `value` equal to true. Otherwise `value` is false.

## Inherited from std::integral_constant

### Member constants

value [static] | true if `T` uses allocator `Alloc`, false otherwise (public static member constant)

### Member functions

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

### Member types

Type | Definition
`value_type` | `bool`
`type` | std::integral_constant<bool, value>

### [edit] Specializations

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:

1) `T` has a constructor which takes std::allocator_arg_t as the first argument, and `Alloc` as the second argument.

2) `T` has a constructor which takes `Alloc` as the last argument.

The following specializations are already provided by the standard library:

std::uses_allocator<std::tuple> (C++11) | specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocator<std::queue> (C++11) | specializes the std::uses_allocator type trait (function template) [edit]
std::uses_allocator<std::priority_queue> (C++11) | specializes the std::uses_allocator type trait (function template) [edit]
std::uses_allocator<std::stack> (C++11) | specializes the std::uses_allocator type trait (function template) [edit]
std::uses_allocator<std::function> (C++11) | specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocator<std::promise> (C++11) | specializes the std::uses_allocator type trait (class template specialization) [edit]
std::uses_allocator<std::packaged_task> (C++11) | specializes the std::uses_allocator type trait (class template specialization) [edit]

### [edit] Notes

This type trait is used by std::scoped_allocator_adaptor and may be used by custom allocators to determine whether the object 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

allocator_arg (C++11) | an object of type std::allocator_arg_t used to select allocator-aware constructors (constant) [edit]
allocator_arg_t (C++11) | tag type used to select allocator-aware constructor overloads (class) [edit]
scoped_allocator_adaptor (C++11) | implements multi-level allocator for multi-level containers (class template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/memory/uses_allocator&oldid=62799"