std::is_assignable, std::is_trivially_assignable, std::is_nothrow_assignable
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <type_traits> 中定义
|
||
template< class T, class U > struct is_assignable; |
(1) | (C++11 起) |
template< class T, class U > struct is_trivially_assignable; |
(2) | (C++11 起) |
template< class T, class U > struct is_nothrow_assignable; |
(3) | (C++11 起) |
如果表达式std::declval<T>() = std::declval<U>()是在未经评估的情况下形成的,为会员提供恒定的
2) value
等于true。对于任何其他类型,value
是false.原文:
If the expression std::declval<T>() = std::declval<U>() is well-formed in unevaluated context, provides the member constant
value
equal true. For any other type, value
is false.1),但评价的赋值表达式不会调用任何操作,是不平凡的.
3) 原文:
same as 1), but evaluation of the assignment expression will not call any operation that is not trivial.
1),但评价的赋值表达式将不会调用任何操作,不noexcept的.
原文:
same as 1), but the evaluation of the assignment expression will not call any operation that is not noexcept.
目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 T is assignable from U ,false其他方式 原文: true if T is assignable from U , false otherwise (公共静态成员常量) |
Member functions
operator bool |
转换的对象bool,返回 value 原文: converts the object to bool, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 示例
#include <iostream> #include <string> #include <type_traits> struct Ex1 { int n; }; int main() { std::cout << std::boolalpha << "int is assignable from double? " << std::is_assignable<int, double>::value << '\n' << "int& is nothrow assignable from double? " << std::is_nothrow_assignable<int&, double>::value << '\n' << "string is assignable from double? " << std::is_assignable<std::string, double>::value << '\n' << "Ex1& is trivially assignable from const Ex1&? " << std::is_trivially_assignable<Ex1&, const Ex1&>::value << '\n'; }
输出:
int is assignable from double? false int& is nothrow assignable from double? true string is assignable from double? true Ex1& is trivially assignable from const Ex1&? true
[编辑] 另请参阅
(C++11) (C++11) (C++11) |
检查对象是否重载了拷贝赋值运算符 (类模板) |
(C++11) (C++11) (C++11) |
检查对象是否重载了移动赋值运算符 (类模板) |