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