定义于头文件
<type_traits>
|
||
template< std::size_t Len, class... Types >
struct aligned_union; |
(C++11 起) | |
提供嵌套类型 type
,它是平凡类型,且其大小和对齐适合用作任何列于 Types
的类型的一个对象的未初始化存储。存储的大小至少为 Len
。 std::aligned_union 亦确定所有 Types
中最严格(最大)的对齐要求,使之可用作常量 alignment_value
。
若 sizeof...(Types) == 0 ,则行为未定义。
是否支持任何扩展对齐是实现定义的。
目录 |
名称 | 定义 |
type
|
适用于存储来自 Types 的任何类型的平凡类型
|
template< std::size_t Len, class... Types >
using aligned_union_t = typename aligned_union<Len,Types...>::type; |
(C++14 起) | |
alignment_value
[静态]
|
所有 Types 的最严格对齐 (公开静态成员常量) |
#include <algorithm> template <std::size_t Len, class... Types> struct aligned_union { static constexpr std::size_t alignment_value = std::max({alignof(Types)...}); struct type { alignas(alignment_value) char _s[std::max({Len, sizeof(Types)...})]; }; }; |
本节未完成 原因:暂无示例 |
(C++11)
|
获取类型的最小对齐字节数 (类模板) |
(C++11)
|
定义适用作给定大小的类型的未初始化存储的类型 (类模板) |