std::is_union
From cppreference.com
| ヘッダ <type_traits> で定義 |
||
| template< class T > struct is_union; |
(C++11以降) | |
std::is_unionはUnaryTypeTraitです。
Tが共用体型であるかをチェックします。Tが共用体型である場合、valueはtrueに等しくなります。そうでない場合、valueはfalseに等しくなります。
プログラムがstd::is_unionまたはstd::is_union_vに特殊化を追加した場合、動作は未定義です。
目次 |
[編集] テンプレートパラメータ
| T | - | チェックする型 |
[編集] ヘルパー変数テンプレート
| template< class T > constexpr bool is_union_v = is_union<T>::value; |
(C++17以降) | |
std::integral_constant から継承
メンバ定数
| value [static] |
Tが共用体型であればtrue、そうでなければfalse(公開静的メンバ定数) |
メンバ関数
| operator bool |
オブジェクトを bool に変換し、value を返します。 (public member function) |
| operator() (C++14) |
value を返します。 (public member function) |
メンバ型
| 型 | 定義 |
value_type
|
bool |
type
|
std::integral_constant<bool, value> |
[編集] 例
このコードを実行
#include <type_traits> struct A {}; static_assert(!std::is_union_v<A>); typedef union { int a; float b; } B; static_assert(std::is_union_v<B>); struct C { B d; }; static_assert(!std::is_union_v<C>); static_assert(!std::is_union_v<int>); int main() {}
[編集] 関連項目
| (C++11) |
型が共用体でないクラス型であるかをチェックする (クラステンプレート) |