std::is_nothrow_move_assignable in C++
The std::is_nothrow_move_assignable template of C++ STL is present in the <type_traits> header file. The std::is_nothrow_move_assignable template of C++ STL is used to check whether the T is a move assignable type or not and this is known for not to throw any exception. It return the boolean value true if T is move assignable type, otherwise return false.
Header File:
#include<type_traits>
Template Class:
template< class T > struct is_move_assignable;
Syntax:
std::is_move_assignable<T>::value
Parameter: The template std::is_nothrow_move_assignable accepts a single parameter T(Trait class) to check whether T is move assignable with no throw exception or not.
Return Value: The template std::is_nothrow_move_assignable returns a boolean variable as shown below:
- True: If the type T is move assignable type.
- False: If the type T is not a move assignable type.
Below is the program to demonstrate std::is_nothrow_move_assignable:
Program:
// C++ program to illustrate // std::is_nothrow_move_assignable #include <bits/stdc++.h> #include <type_traits> using namespace std; // Declare structures struct A { }; struct B { B& operator=(B&) = delete ; }; struct Ex1 { Ex1() {} Ex1(Ex1&&) { cout << "Throwing move constructor!" ; } Ex1( const Ex1&) { cout << "Throwing copy constructor!" ; } }; struct Ex2 { Ex2() {} Ex2(Ex2&&) noexcept { cout << "Non-throwing move constructor!" ; } Ex2( const Ex2&) noexcept { cout << "Non-throwing copy constructor!" ; } }; // Driver Code int main() { cout << boolalpha; // Check if int is a move // assignable or not cout << "int: " << is_nothrow_move_assignable< int >::value << endl; // Check if struct A is a move // assignable or not cout << "struct A: " << is_nothrow_move_assignable<A>::value << endl; // Check if struct B is a move // assignable or not cout << "struct B: " << is_nothrow_move_assignable<B>::value << endl; // Check if struct Ex1 is a move // assignable or not cout << "struct Ex1: " << is_nothrow_move_assignable<Ex1>::value << endl; // Check if struct Ex2 is a move // assignable or not cout << "struct Ex2: " << is_nothrow_move_assignable<Ex2>::value << endl; return 0; } |
int: true struct A: true struct B: false struct Ex1: false struct Ex2: false
Reference: http://www.cplusplus.com/reference/type_traits/is_nothrow_move_assignable/
Please Login to comment...