std::is_standard_layout
提供: cppreference.com
ヘッダ <type_traits> で定義
|
||
template< class T > struct is_standard_layout; |
(C++11以上) | |
T
が標準レイアウト型 (つまり、スカラー型、標準レイアウトクラス、またはそれらの配列、またはそれらの cv 修飾された型) であれば、 true に等しいメンバ定数 value
が提供されます。 それ以外の型に対しては、 value
は false です。
標準レイアウトクラスは StandardLayoutType を満たすクラスです。
std::remove_all_extents_t<T> が不完全型であり、 void (または cv 修飾された void) でない場合、動作は未定義です。
目次 |
[編集] テンプレート引数
T | - | 調べる型 |
[編集] ヘルパー変数テンプレート
template< class T > inline constexpr bool is_standard_layout_v = is_standard_layout<T>::value; |
(C++17以上) | |
std::integral_constant から継承
メンバ定数
value [静的] |
T が標準レイアウト型ならば true、そうでなければ false (パブリック静的メンバ定数) |
メンバ関数
operator bool |
オブジェクトを bool に変換します。 value を返します (パブリックメンバ関数) |
operator() (C++14) |
value を返します (パブリックメンバ関数) |
メンバ型
型 | 定義 |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
[編集] ノート
標準レイアウトクラスへのポインタは、その最初の非静的データメンバへのポインタに (reinterpret_cast を用いて) 変換することができ、その逆もできます。
ある標準レイアウト共用体が2つ以上の標準レイアウト構造体を保持する場合、それらの共通の最初の部分を調べることができます。
マクロ offsetof は標準レイアウトクラスでのみ使用することができます。
[編集] 例
Run this code
#include <iostream> #include <type_traits> struct A { int m; }; struct B { int m1; private: int m2; }; struct C { virtual void foo(); }; int main() { std::cout << std::boolalpha; std::cout << std::is_standard_layout<A>::value << '\n'; std::cout << std::is_standard_layout<B>::value << '\n'; std::cout << std::is_standard_layout<C>::value << '\n'; }
出力:
true false false
[編集] 関連項目
(C++11) |
型がトリビアルにコピー可能かどうか調べます (クラステンプレート) |
(C++11)(C++20で非推奨) |
型が POD (plain-old data) 型かどうか調べます (クラステンプレート) |
標準レイアウト型の先頭から指定されたメンバまでのバイトオフセット (関数マクロ) |