型に自明な既定コンストラクターが存在するかどうかをテストします。
template<class Ty>
struct has_trivial_constructor;
パラメーター
- Ty
問い合わせる型。
解説
型 Ty が自明なコンストラクターを持ったクラスである場合、型述語のインスタンスは true を保持します。それ以外の場合は、false を保持します。
クラス Ty のコンストラクターは、次の条件を満たしていれば、自明なコンストラクターです。
暗黙的に宣言された既定のコンストラクターである。
クラス Ty に仮想関数が存在しない。
クラス Ty に仮想基本クラスが存在しない。
Ty クラスのすべての直接基本クラスに、自明なコンストラクターが存在する。
クラス型のすべての非静的データ メンバーのクラスに自明なコンストラクターが存在する。
クラスの配列型のすべての非静的データ メンバーのクラスに自明なコンストラクターが存在する。
使用例
// std_tr1__type_traits__has_trivial_constructor.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>
struct trivial
{
int val;
};
struct throws
{
throws() throw(int)
{
}
throws(const throws&) throw(int)
{
}
throws& operator=(const throws&) throw(int)
{
}
int val;
};
int main()
{
std::cout << "has_trivial_constructor<trivial> == " << std::boolalpha
<< std::has_trivial_constructor<trivial>::value << std::endl;
std::cout << "has_trivial_constructor<throws> == " << std::boolalpha
<< std::has_trivial_constructor<throws>::value << std::endl;
return (0);
}
必要条件
ヘッダー : <type_traits>
名前空間: std