class template
<type_traits>
std::aligned_storagetemplate <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.
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;
}
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