std::aligned_union
提供: cppreference.com
ヘッダ <type_traits> で定義 | ||
template<std::size_t Len, class... Types> struct aligned_union; | (C++11以上) | |
Types
にリストされた任意の型のオブジェクトのための未初期化記憶域として使用するのに適したサイズとアライメントのトリビアルな標準レイアウト型であるメンバ型 type
を提供します。 記憶域のサイズは少なくとも Len
です。 std::aligned_union はすべての Types
のうち最も厳しい (大きな) アライメント要件を調べ、定数 alignment_value
として利用できるようにします。
sizeof...(Types)==0 の場合、または Types
の型のいずれかが完全オブジェクト型でない場合、動作は未定義です。
任意の拡張アライメントがサポートされるかどうかは処理系定義です。
目次 |
[編集]メンバ型
名前 | 定義 |
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 {staticconstexprstd::size_t alignment_value =std::max({alignof(Types)...}); struct type { alignas(alignment_value)char _s[std::max({Len, sizeof(Types)...})];};}; |
[編集]例
This section is incomplete Reason: no example |
[編集] 欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
LWG 2979 | C++11 | complete type wasn't required | requires complete types |
[編集]関連項目
(C++11) | 型のアライメント要件を取得します (クラステンプレート) |
(C++11) | 指定されたサイズの未初期化記憶域として使用するのに適した型を定義します (クラステンプレート) |