---
name: "__gnu_cxx::__alloc_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/__gnu_cxx::__alloc_traits/3cxx"
---

# \_\_gnu\_cxx::\_\_alloc\_traits(3cxx)

Uniform interface to C++98 and C++11 allocators.

## NAME

\_\_gnu\_cxx::\_\_alloc\_traits\< \_Alloc, typename \> - Uniform interface to C++98 and C++11 allocators.

## SYNOPSIS

`#include <alloc_traits.h>`

Inherits **std::allocator\_traits\< \_Alloc \>**.

### Public Types

typedef **std::allocator\_traits**\< \_Alloc \> **\_Base\_type**\
 typedef \_Alloc **allocator\_type**\
 typedef **\_Base\_type::const\_pointer** **const\_pointer**\
 typedef const value\_type & **const\_reference**\
 using **const\_void\_pointer** = typename \_Ptr\< \_\_cv\_pointer, const void \>::type\
 The allocator's const void pointer type.  typedef **\_Base\_type::difference\_type** **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.  typedef **\_Base\_type::pointer** **pointer**\
 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 \> \>\
 typedef value\_type & **reference**\
 typedef **\_Base\_type::size\_type** **size\_type**\
 typedef **\_Base\_type::value\_type** **value\_type**\
 using **void\_pointer** = typename \_Ptr\< \_\_v\_pointer, void \>::type\
 The allocator's void pointer type.

### Static Public Member Functions

static constexpr bool **\_S\_always\_equal** ()\
 static constexpr bool **\_S\_nothrow\_move** ()\
 static constexpr void **\_S\_on\_swap** (\_Alloc &\_\_a, \_Alloc &\_\_b)\
 static constexpr bool **\_S\_propagate\_on\_copy\_assign** ()\
 static constexpr bool **\_S\_propagate\_on\_move\_assign** ()\
 static constexpr bool **\_S\_propagate\_on\_swap** ()\
 static constexpr \_Alloc **\_S\_select\_on\_copy** (const \_Alloc &\_\_a)\
 static constexpr pointer **allocate** (\_Alloc &\_\_a, size\_type \_\_n)\
 Allocate memory.  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 pointer **allocate** (\_Alloc &\_\_a, size\_type \_\_n, **const\_void\_pointer** \_\_hint)\
 Allocate memory.  template\<typename \_Ptr , typename... \_Args\> static constexpr **std::\_\_enable\_if\_t**\< **\_\_is\_custom\_pointer**\< \_Ptr \>::value \> **construct** (\_Alloc &\_\_a, \_Ptr \_\_p, \_Args &&... \_\_args) noexcept(noexcept(\_Base\_type::construct(\_\_a, std::\_\_to\_address(\_\_p), **std::forward**\< \_Args \>(\_\_args)...)))\
 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.  static constexpr void **deallocate** (\_Alloc &\_\_a, pointer \_\_p, size\_type \_\_n)\
 Deallocate memory.  template\<typename \_Ptr \> static constexpr **std::\_\_enable\_if\_t**\< **\_\_is\_custom\_pointer**\< \_Ptr \>::value \> **destroy** (\_Alloc &\_\_a, \_Ptr \_\_p) noexcept(noexcept(\_Base\_type::destroy(\_\_a, std::\_\_to\_address(\_\_p))))\
 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, typename = typename \_Alloc::value\_type\>

struct \_\_gnu\_cxx::\_\_alloc\_traits\< \_Alloc, typename \>"Uniform interface to C++98 and C++11 allocators.

## Member Typedef Documentation

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

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 \>::is\_always\_equal = typename \_\_detected\_or\_t\<is\_empty\<\_Alloc\>, \_\_equal, \_Alloc\>::type` [inherited]`

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 \>::propagate\_on\_container\_copy\_assignment = \_\_detected\_or\_t\<false\_type, \_\_pocca, \_Alloc\>` [inherited]`

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\>` [inherited]`

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\>` [inherited]`

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 \>::void\_pointer = typename \_Ptr\<\_\_v\_pointer, void\>::type` [inherited]`

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]`, ` [inherited]`

Allocate memory.

**Parameters**

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

Calls `a.allocate(n)`

### template\<typename \_Alloc , typename = typename \_Alloc::value\_type\> 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]`, ` [inherited]`

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 , typename = typename \_Alloc::value\_type\> 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 , typename = typename \_Alloc::value\_type\> 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]`, ` [inherited]`

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 , typename = typename \_Alloc::value\_type\> 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 , typename = typename \_Alloc::value\_type\> 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 , typename = typename \_Alloc::value\_type\> 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()`

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::max\_size()**, and **std::list\< \_Tp, \_Alloc \>::max\_size()**.

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

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.
