class template
<type_traits>
std::aligned_uniontemplate <size_t Len, class... Types> struct aligned_union;
Aligned union
Obtains a POD type suitable for use as storage for any object whose type is listed in Types, and a size of at least Len.The obtained type is aliased as member type aligned_union::type.
Notice that this type is not a union, but the type that could hold the data of such a union.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// aligned_union example
#include <iostream>
#include <type_traits>
union U {
int i;
char c;
double d;
U(const char* str) : c(str[0]) {}
}; // non-POD
typedef std::aligned_union<sizeof(U),int,char,double>::type U_pod;
int main() {
U_pod a,b; // default-initialized (ok: type is POD)
new (&a) U ("hello"); // call U's constructor in place
b = a; // assignment (ok: type is POD)
std::cout << reinterpret_cast<U&>(b).i << 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