A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/type_traits/aligned_storage/ below:

class template

<type_traits>

std::aligned_storage
template <size_t Len, size_t Align = /* default alignment */>struct aligned_storage;

Aligned storage

Obtains a POD type suitable to use as storage for an object of a size of at most Len bytes, aligned as specified by Align.

The obtained type is aliased as member type aligned_storage::type.

If Align is omitted, the most stringent alignment requirement for any C++ object type whose size is no greater than Len is used as default alignment.



Template parameters
Len
The size of the storage object, in bytes.
This shall not be zero.
size_t is an unsigned integral type.
Align
The alignment requested, in bytes. The actual alignment used may be a divisor of this value.
size_t is an unsigned integral type.

Member types member type definition type A POD type suitable to store Len bytes, aligned as specified by Align.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// aligned_storage example
#include <iostream>
#include <type_traits>

struct A {  // non-POD type
  int avg;
  A (int a, int b) : avg((a+b)/2) {}
};

typedef std::aligned_storage<sizeof(A),alignof(A)>::type A_pod;

int main() {
  A_pod a,b;
  new (&a) A (10,20);
  b=a;
  std::cout << reinterpret_cast<A&>(b).avg << std::endl;

  return 0;
}

Output:


See also
aligned_union
Aligned union (class template)
is_pod
Is POD type (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4