---
name: "std::allocator_traits"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::allocator_traits"
---

# std::allocator\_traits(3)

Uniform interface to all allocator types.

## NAME

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

## SYNOPSIS

\#include \<memory\>

Inherited by **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Char\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_CharT\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Node\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Bit\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Tp\_alloc\_type \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Map\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Pair\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Key\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Val\_alloc\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Node\_allocator \>**, **\_\_gnu\_cxx::pointer\< \_Tp\_alloc\_type \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< allocator\_type \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::other\< \_Alloc \>**, **\_\_gnu\_cxx::\_\_alloc\_traits\< std::allocator\< value\_type \> \>**, and **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Alloc, typename \>**.

### Public Types

typedef \_Alloc **allocator\_type**\
 The allocator type.  using **const\_pointer**\
 The allocator's const pointer type.  using **const\_void\_pointer**\
 The allocator's const void pointer type.  using **difference\_type**\
 The allocator's difference type.  using **is\_always\_equal**\
 Whether all instances of the allocator type compare equal.  using **pointer**\
 The allocator's pointer type.  using **propagate\_on\_container\_copy\_assignment**\
 How the allocator is propagated on copy assignment.  using **propagate\_on\_container\_move\_assignment**\
 How the allocator is propagated on move assignment.  using **propagate\_on\_container\_swap**\
 How the allocator is propagated on swap.  template\<typename \_Tp\> using **rebind\_alloc**\
 template\<typename \_Tp\> using **rebind\_traits**\
 using **size\_type**\
 The allocator's size type.  typedef \_Alloc::value\_type **value\_type**\
 The allocated type.  using **void\_pointer**\
 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.  static constexpr auto **allocate\_at\_least** (\_Alloc &\_\_a, **size\_type** \_\_n) -\> allocation\_result\< **pointer**, **size\_type** \>\
 Allocate memory, generously.  template\<typename \_Tp, typename... \_Args\> static constexpr void **construct** (\_Alloc &\_\_a, \_Tp \*\_\_p, \_Args &&... \_\_args) noexcept(\_S\_nothrow\_construct\< \_Tp, \_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(\_S\_nothrow\_destroy\< \_Tp \>())\
 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

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

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

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

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

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

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

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

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

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

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\> constexpr pointer std::allocator\_traits\< \_Alloc \>::allocate (\_Alloc & \_\_a, size\_type \_\_n) \[inline\], \[static\], \[nodiscard\], \[constexpr\]

Allocate memory.

**Parameters**

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

Calls a.allocate(n)

### template\<typename \_Alloc\> constexpr pointer std::allocator\_traits\< \_Alloc \>::allocate (\_Alloc & \_\_a, size\_type \_\_n, const\_void\_pointer \_\_hint) \[inline\], \[static\], \[nodiscard\], \[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\> constexpr auto std::allocator\_traits\< \_Alloc \>::allocate\_at\_least (\_Alloc & \_\_a, size\_type \_\_n) -\> allocation\_result\< pointer, size\_type \> \[inline\], \[static\], \[nodiscard\], \[constexpr\]

Allocate memory, generously.

**Parameters**

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

**Returns**

Memory of suitable size and alignment for n or more contiguous objects of type value\_type.

Returns a.allocate\_at\_least(n) if that expression is well-formed, else { a.allocate(n), n }. When an allocator is obliged to reserve more space than required for the cited n objects, it may deliver the extra space to the caller.

### template\<typename \_Alloc\> template\<typename \_Tp, typename... \_Args\> constexpr void std::allocator\_traits\< \_Alloc \>::construct (\_Alloc & \_\_a, \_Tp \* \_\_p, \_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\> 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\> 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\> 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\> 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.
