std::is_nothrow_move_constructible in C++ with Example
Last Updated :
14 Feb, 2022
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
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct B {
};
struct A {
A& operator=(A&) = delete ;
};
struct C {
C(C&&) {}
};
struct D {
D(D&&) = delete ;
};
int main()
{
cout << boolalpha;
cout << " int : "
<< is_nothrow_move_constructible< int >::value
<< endl;
cout << " char : "
<< is_nothrow_move_constructible< char >::value
<< endl;
cout << " float : "
<< is_nothrow_move_constructible< float >::value
<< endl;
cout << " struct A is nothrow move constructible? "
<< is_nothrow_move_constructible<A>::value
<< endl;
cout << " struct B is nothrow move constructible? "
<< is_nothrow_move_constructible<B>::value
<< endl;
cout << " struct C is nothrow move constructible? "
<< is_nothrow_move_constructible<C>::value
<< endl;
cout << " struct D is nothrow move constructible? "
<< is_nothrow_move_constructible<D>::value
<< endl;
return 0;
}
|
Output:
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/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...