std::is_copy_assignable, std::is_trivially_copy_assignable, std::is_nothrow_copy_assignable
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <type_traits> 中定义
|
||
template< class T > struct is_copy_assignable; |
(1) | (C++11 起) |
template< class T > struct is_trivially_copy_assignable; |
(2) | (C++11 起) |
template< class T > struct is_nothrow_copy_assignable; |
(3) | (C++11 起) |
检查一个类型是否是
2) CopyAssignable
,即有一个可访问的显式或隐式的拷贝赋值运算符。如果符合要求,一个成员value
等于true,否则value
是false.原文:
Checks whether a type is
CopyAssignable
, i.e. has an accessible explicit or implicit copy assignment operator. If the requirement is met, a member constant value
equal true is provided, otherwise value
is false.同为1),但评价的拷贝赋值表达式不会调用任何操作,是不平凡的.
3) 原文:
Same as 1), but evaluation of the copy-assignment expression will not call any operation that is not trivial.
同为1),但评价的拷贝赋值表达式的不叫任何操作,不noexcept的.
原文:
Same as 1), but the evaluation of the copy-assignment expression will not call any operation that is not noexcept.
目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 T is copy-assignable,false其他方式 原文: true if T is copy-assignable, 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>
[编辑] 可能的实现
template< class T> struct is_copy_assignable : std::is_assignable< typename std::add_lvalue_reference<T>::type, const typename std::add_lvalue_reference<T>::type> {}; template< class T> struct is_trivially_copy_assignable : std::is_trivially_assignable< typename std::add_lvalue_reference<T>::type, const typename std::add_lvalue_reference<T>::type> {}; template< class T> struct is_nothrow_copy_assignable : std::is_nothrow_assignable< typename std::add_lvalue_reference<T>::type, const typename std::add_lvalue_reference<T>::type> {}; |
[编辑] 示例
#include <iostream> #include <utility> #include <type_traits> struct Foo { int n; }; int main() { std::cout << std::boolalpha << "Foo is trivally copy-assignable? " << std::is_trivially_copy_assignable<Foo>::value << '\n' << "int[2] is copy-assignable? " << std::is_copy_assignable<int[2]>::value << '\n' << "int is nothrow copy-assignable? " << std::is_nothrow_copy_assignable<int>::value << '\n'; }
输出:
Foo is trivally copy-assignable? true int[2] is copy-assignable? false int is nothrow copy-assignable? true
[编辑] 另请参阅
(C++11) (C++11) (C++11) |
检查对象是否重载了特定参数的赋值运算符 (类模板) |
(C++11) (C++11) (C++11) |
检查对象是否重载了移动赋值运算符 (类模板) |