std::aligned_storage< _Len, _Align > Struct Template Reference
Utilities » Metaprogramming

`#include <type_traits>`

## Detailed Description

template<size_t _Len, size_t _Align = __aligned_storage_default_alignment(_Len)>
struct std::aligned_storage< _Len, _Align >

Aligned storage.

The member typedef type is be a POD type suitable for use as uninitialized storage for any object whose size is at most _Len and whose alignment is a divisor of _Align.

It is important to use the nested type as uninitialized storage, not the std::aligned_storage type itself which is an empty class with 1-byte alignment. So this is correct:

typename std::aligned_storage<sizeof(X), alignof(X)>::type m_xobj;

This is wrong:

std::aligned_storage<sizeof(X), alignof(X)> m_xobj;

In C++14 and later std::aligned_storage_t<sizeof(X), alignof(X)> can be used to refer to the type member typedef.

The default value of _Align is supposed to be the most stringent fundamental alignment requirement for any C++ object type whose size is no greater than _Len (see [basic.align] in the C++ standard).

Deprecated
  Deprecated in C++23. Uses can be replaced by an array std::byte[_Len] declared with alignas(_Align).

Definition at line 2420 of file type_traits.

The documentation for this struct was generated from the following file:

- type_traits