std::is_move_assignable, std::is_trivially_move_assignable, std::is_nothrow_move_assignable
From cppreference.com
Defined in header
<type_traits>
|
||
template< class T >
struct is_move_assignable; |
(1) | (since C++11) |
template< class T >
struct is_trivially_move_assignable; |
(2) | (since C++11) |
template< class T >
struct is_nothrow_move_assignable; |
(3) | (since C++11) |
1) 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.
2) same as 1), but evaluation of the move-assignment expression will not call any operation that is not trivial.
3) same as 1), but the evaluation of the move-assignment expression will not call any operation that is not noexcept.
Contents |
Inherited from std::integral_constant
Member constants
value
[static]
|
true if T is move-assignable, false otherwise (public static member constant) |
Member functions
operator bool |
converts the object to bool, returns value (public member function) |
Member types
Type | Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
[edit] Possible implementation
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> {}; |
[edit] Example
Run this code
#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'; }
Output:
std::string is nothrow move-assignable? true int[2] is move-assignable? false Foo is trivially move-assignable? true
[edit] See also
(C++11)(C++11)(C++11)
|
checks if a type has a assignment operator for a specific argument (class template) |
(C++11)(C++11)(C++11)
|
checks if a type has a copy assignment operator (class template) |