测试分配时是否不引发类型。
语法
template<class Ty>
struct has_nothrow_assign;
参数
- Ty
要查询的类型。
备注
如果类型 Ty 具有 nothrow 复制赋值运算符,类型谓词的实例将保持为 true,否则保持为 false。
Nothrow 函数是一个具有空引发说明符的函数,或是一个编译器可以决定将不会引发异常的函数。
// 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);
}
has_nothrow_assign<不重要> == true has_nothrow_assign<引发> == false
要求
标头:<type_traits>
命名空间: std