has_nothrow_assign クラス
代入時に例外がスローされない型であるかどうかをテストします。
template<class Ty>
struct has_nothrow_assign;
パラメーター
- Ty
問い合わせる型。
解説
型 Ty が nothrow のコピー代入演算子を持つ場合、型述語のインスタンスは true を保持します。それ以外の場合は、false を保持します。
nothrow 関数とは、空の throw 指定子を持っているなど、例外がスローされない関数であることをコンパイラが何らかの手段で判断できる関数をいいます。
使用例
// std_tr1__type_traits__has_nothrow_assign.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_nothrow_assign<trivial> == " << std::boolalpha
<< std::has_nothrow_assign<trivial>::value << std::endl;
std::cout << "has_nothrow_assign<throws> == " << std::boolalpha
<< std::has_nothrow_assign<throws>::value << std::endl;
return (0);
}
必要条件
ヘッダー : <type_traits>
名前空間: std