---
name: "std::allocator_traits"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::allocator_traits/3cxx"
---

# std::allocator\_traits(3cxx)

Uniform interface to all allocator types.

## NAME

std::allocator\_traits\< \_Alloc \> - Uniform interface to all allocator types.

## SYNOPSIS

`#include <memory>`

Inherits \_\_allocator\_traits\_base.

Inherited by **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Tp\_alloc\_type \>**, and **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Alloc, typename \>**.

### Public Types

**typedef** \_Alloc **allocator\_type**\
 The allocator type.  **using** **const\_pointer** = **typename** \_Ptr\< **\_\_c\_pointer**, const **value\_type** \>::type\
 The allocator's const pointer type.  **using** **const\_void\_pointer** = **typename** \_Ptr\< **\_\_cv\_pointer**, const **void** \>::type\
 The allocator's const void pointer type.  **using** **difference\_type** = **typename** \_Diff\< \_Alloc, **pointer** \>::type\
 The allocator's difference type.  **using** **is\_always\_equal** = **typename** **\_\_detected\_or\_t**\< **is\_empty**\< \_Alloc \>, \_\_equal, \_Alloc \>::type\
 Whether all instances of the allocator type compare equal.  **using** **pointer** = **\_\_detected\_or\_t**\< **value\_type** \*, \_\_pointer, \_Alloc \>\
 The allocator's pointer type.  **using** **propagate\_on\_container\_copy\_assignment** = **\_\_detected\_or\_t**\< **false\_type**, **\_\_pocca**, \_Alloc \>\
 How the allocator is propagated on copy assignment.  **using** **propagate\_on\_container\_move\_assignment** = **\_\_detected\_or\_t**\< **false\_type**, **\_\_pocma**, \_Alloc \>\
 How the allocator is propagated on move assignment.  **using** **propagate\_on\_container\_swap** = **\_\_detected\_or\_t**\< **false\_type**, **\_\_pocs**, \_Alloc \>\
 How the allocator is propagated on swap.  template\<**typename** \_Tp \> **using** **rebind\_alloc** = **\_\_alloc\_rebind**\< \_Alloc, \_Tp \>\
 template\<**typename** \_Tp \> **using** **rebind\_traits** = **allocator\_traits**\< **rebind\_alloc**\< \_Tp \> \>\
 **using** **size\_type** = **typename** \_Size\< \_Alloc, **difference\_type** \>::type\
 The allocator's size type.  **typedef** \_Alloc::value\_type **value\_type**\
 The allocated type.  **using** **void\_pointer** = **typename** \_Ptr\< **\_\_v\_pointer**, **void** \>::type\
 The allocator's void pointer type.

### Static Public Member Functions

**static** constexpr **pointer** **allocate** (\_Alloc &\_\_a, **size\_type** \_\_n)\
 Allocate memory.  **static** constexpr **pointer** **allocate** (\_Alloc &\_\_a, **size\_type** \_\_n, **const\_void\_pointer** **\_\_hint**)\
 Allocate memory.  template\<**typename** \_Tp , typename... \_Args\> **static** constexpr **auto** **construct** (\_Alloc &\_\_a, \_Tp \*\_\_p, **\_Args** &&... **\_\_args**) noexcept(noexcept(\_S\_construct(\_\_a, \_\_p, **std::forward**\< **\_Args** \>(**\_\_args**)...))) -\> **decltype**(\_S\_construct(\_\_a, \_\_p, **std::forward**\< **\_Args** \>(**\_\_args**)...))\
 Construct an object of type `_Tp`  **static** constexpr **void** **deallocate** (\_Alloc &\_\_a, **pointer** \_\_p, **size\_type** \_\_n)\
 Deallocate memory.  template\<**typename** \_Tp \> **static** constexpr **void** **destroy** (\_Alloc &\_\_a, \_Tp \*\_\_p) noexcept(noexcept(\_S\_destroy(\_\_a, \_\_p, 0)))\
 Destroy an object of type *\_Tp*.  **static** constexpr **size\_type** **max\_size** (const \_Alloc &\_\_a) noexcept\
 The maximum supported allocation size.  **static** constexpr \_Alloc **select\_on\_container\_copy\_construction** (const \_Alloc &**\_\_rhs**)\
 Obtain an allocator to use when copying a container.

## Detailed Description

### template\<typename \_Alloc\>

struct std::allocator\_traits\< \_Alloc \>"Uniform interface to all allocator types.

**Since**

C++11

## Member Typedef Documentation

### template\<typename \_Alloc \> typedef \_Alloc std::allocator\_traits\< \_Alloc \>::allocator\_type

The allocator type.

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::const\_pointer = typename \_Ptr\<\_\_c\_pointer, const value\_type\>::type

The allocator's const pointer type. `Alloc::const_pointer` if that type exists, otherwise ` pointer_traits<pointer>::rebind<const value_type> `

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::const\_void\_pointer = typename \_Ptr\<\_\_cv\_pointer, const void\>::type

The allocator's const void pointer type. `Alloc::const_void_pointer` if that type exists, otherwise ` pointer_traits<pointer>::rebind<const void> `

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::difference\_type = typename \_Diff\<\_Alloc, pointer\>::type

The allocator's difference type. `Alloc::difference_type` if that type exists, otherwise ` pointer_traits<pointer>::difference_type `

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::is\_always\_equal = typename \_\_detected\_or\_t\<is\_empty\<\_Alloc\>, \_\_equal, \_Alloc\>::type

Whether all instances of the allocator type compare equal. `Alloc::is_always_equal` if that type exists, otherwise `is_empty<Alloc>::type`

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::pointer = \_\_detected\_or\_t\<value\_type\*, \_\_pointer, \_Alloc\>

The allocator's pointer type. `Alloc::pointer` if that type exists, otherwise `value_type*`

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::propagate\_on\_container\_copy\_assignment = \_\_detected\_or\_t\<false\_type, \_\_pocca, \_Alloc\>

How the allocator is propagated on copy assignment. `Alloc::propagate_on_container_copy_assignment` if that type exists, otherwise `false_type`

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::propagate\_on\_container\_move\_assignment = \_\_detected\_or\_t\<false\_type, \_\_pocma, \_Alloc\>

How the allocator is propagated on move assignment. `Alloc::propagate_on_container_move_assignment` if that type exists, otherwise `false_type`

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::propagate\_on\_container\_swap = \_\_detected\_or\_t\<false\_type, \_\_pocs, \_Alloc\>

How the allocator is propagated on swap. `Alloc::propagate_on_container_swap` if that type exists, otherwise `false_type`

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::size\_type = typename \_Size\<\_Alloc, difference\_type\>::type

The allocator's size type. `Alloc::size_type` if that type exists, otherwise ` make_unsigned<difference_type>::type `

### template\<typename \_Alloc \> typedef \_Alloc::value\_type std::allocator\_traits\< \_Alloc \>::value\_type

The allocated type.

### template\<typename \_Alloc \> using std::allocator\_traits\< \_Alloc \>::void\_pointer = typename \_Ptr\<\_\_v\_pointer, void\>::type

The allocator's void pointer type. `Alloc::void_pointer` if that type exists, otherwise ` pointer_traits<pointer>::rebind<void> `

## Member Function Documentation

### template\<typename \_Alloc \> static constexpr pointer std::allocator\_traits\< \_Alloc \>::allocate (\_Alloc & \_\_a, size\_type \_\_n)` [inline]`, ` [static]`, ` [constexpr]`

Allocate memory.

**Parameters**

*\_\_a* An allocator. \
 *\_\_n* The number of objects to allocate space for.

Calls `a.allocate(n)`

### template\<typename \_Alloc \> static constexpr pointer std::allocator\_traits\< \_Alloc \>::allocate (\_Alloc & \_\_a, size\_type \_\_n, const\_void\_pointer \_\_hint)` [inline]`, ` [static]`, ` [constexpr]`

Allocate memory.

**Parameters**

*\_\_a* An allocator. \
 *\_\_n* The number of objects to allocate space for. \
 *\_\_hint* Aid to locality.

**Returns**

Memory of suitable size and alignment for *n* objects of type `value_type`

Returns ` a.allocate(n, hint) ` if that expression is well-formed, otherwise returns `a.allocate(n)`

### template\<typename \_Alloc \> template\<typename \_Tp , typename... \_Args\> static constexpr auto std::allocator\_traits\< \_Alloc \>::construct (\_Alloc & \_\_a, \_Tp \* \_\_p, \_Args &&... \_\_args) -\> decltype(\_S\_construct(\_\_a, \_\_p, std::forward\<\_Args\>(\_\_args)...))

	` [inline]`, ` [static]`, ` [constexpr]`, ` [noexcept]`"

Construct an object of type `_Tp`

**Parameters**

*\_\_a* An allocator. \
 *\_\_p* Pointer to memory of suitable size and alignment for Tp \
 *\_\_args* Constructor arguments.

Calls ` __a.construct(__p, std::forward<Args>(__args)...) ` if that expression is well-formed, otherwise uses placement-new to construct an object of type *\_Tp* at location *\_\_p* from the arguments *\_\_args*...

### template\<typename \_Alloc \> static constexpr void std::allocator\_traits\< \_Alloc \>::deallocate (\_Alloc & \_\_a, pointer \_\_p, size\_type \_\_n)` [inline]`, ` [static]`, ` [constexpr]`

Deallocate memory.

**Parameters**

*\_\_a* An allocator. \
 *\_\_p* Pointer to the memory to deallocate. \
 *\_\_n* The number of objects space was allocated for.

Calls ` a.deallocate(p, n) `

### template\<typename \_Alloc \> template\<typename \_Tp \> static constexpr void std::allocator\_traits\< \_Alloc \>::destroy (\_Alloc & \_\_a, \_Tp \* \_\_p)` [inline]`, ` [static]`, ` [constexpr]`, ` [noexcept]`

Destroy an object of type *\_Tp*.

**Parameters**

*\_\_a* An allocator. \
 *\_\_p* Pointer to the object to destroy

Calls `__a.destroy(__p)` if that expression is well-formed, otherwise calls `__p->~_Tp()`

### template\<typename \_Alloc \> static constexpr size\_type std::allocator\_traits\< \_Alloc \>::max\_size (const \_Alloc & \_\_a)` [inline]`, ` [static]`, ` [constexpr]`, ` [noexcept]`

The maximum supported allocation size.

**Parameters**

*\_\_a* An allocator.

**Returns**

`__a.max_size()` or `numeric_limits<size_type>::max()`

Returns `__a.max_size()` if that expression is well-formed, otherwise returns `numeric_limits<size_type>::max()`

### template\<typename \_Alloc \> static constexpr \_Alloc std::allocator\_traits\< \_Alloc \>::select\_on\_container\_copy\_construction (const \_Alloc & \_\_rhs)` [inline]`, ` [static]`, ` [constexpr]`

Obtain an allocator to use when copying a container.

**Parameters**

*\_\_rhs* An allocator.

**Returns**

`__rhs.select_on_container_copy_construction()` or *\_\_rhs*

Returns `__rhs.select_on_container_copy_construction()` if that expression is well-formed, otherwise returns *\_\_rhs*

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
