std::is_nothrow_move_constructible in C++ with Example
The std::is_nothrow_move_constructible template of C++ STL is present in the <type_traits> header file. The std::is_nothrow_move_constructible template of C++ STL is used to check whether the given type T T is move constructibe or not and this is known for not to throw any exception. It return the boolean value true if T is a move constructible type, Otherwise it return false.
Header File:
#include<type_traits>
Template Class:
template <class T> struct is_nothrow_move_constructible;
Syntax:
std::is_nothrow_move_constructible<T>::value
Parameters: The template std::is_nothrow_move_constructible accepts a single parameter T(Trait class) to check whether T is a move constructible type or not.
Return Value: This template returns a boolean variable as shown below:
- True: If the type T is a move constructible type.
- False: If the type T is not a move constructible type.
Below is the program to illustrates the std::is_nothrow_default_constructible template in C/C++:
Program:
CPP
// C++ program to illustrate // std::is_nothrow_move_constructible #include <bits/stdc++.h> #include <type_traits> using namespace std; // Declare structures struct B { }; struct A { A& operator=(A&) = delete ; }; struct C { C(C&&) {} }; struct D { D(D&&) = delete ; }; // Driver Code int main() { cout << boolalpha; // Check if int is no throw move // constructible or not cout << " int : " << is_nothrow_move_constructible< int >::value << endl; // Check if char is no throw move // constructible or not cout << " char : " << is_nothrow_move_constructible< char >::value << endl; // Check if float is no throw move // constructible or not cout << " float : " << is_nothrow_move_constructible< float >::value << endl; // Check if struct A is no throw // move constructible or not cout << " struct A is nothrow move constructible? " << is_nothrow_move_constructible<A>::value << endl; // Check if struct B is no throw // move constructible or not cout << " struct B is nothrow move constructible? " << is_nothrow_move_constructible<B>::value << endl; // Check if struct C is no throw // move constructible or not cout << " struct C is nothrow move constructible? " << is_nothrow_move_constructible<C>::value << endl; // Check if struct D is no throw // move constructible or not cout << " struct D is nothrow move constructible? " << is_nothrow_move_constructible<D>::value << endl; return 0; } |
int: true char: true float: true struct A is nothrow move constructible? true struct B is nothrow move constructible? true struct C is nothrow move constructible? false struct D is nothrow move constructible? false
Reference: http://www.cplusplus.com/reference/type_traits/is_nothrow_move_constructible/
Please Login to comment...