std::is_move_constructible in C++ with Examples
Last Updated :
12 Jun, 2020
The std::is_move_constructible template of C++ STL is present in the <type_traits> header file. The std::is_move_constructible template of C++ STL is used to check whether the T is move constructible (that can be constructed from an rvalue reference of its type) or not. It returns the boolean value either true or false.
Header File:
#include<type_traits>
Template Class:
template< class T >
struct is_move_convertible;
Syntax:
std::is_move_constructible< datatype >::value << '\n'
Parameters: The template std::is_move_constructible accepts a single parameter T (Trait class) to check whether T is move constructible type or not.
Return Value:
- True: If a given data type T is is_move_constructible.
- False: If a given data type T is not is_move_constructible.
Below is the program to demonstrate std::is_move_constructible:
Program:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct B {
};
struct A {
A& operator=(A&) = delete ;
};
class C {
int n;
C(C&&) = default ;
};
class D {
D( const D&) {}
};
int main()
{
cout << boolalpha;
cout << "char: "
<< is_move_constructible< char >::value
<< endl;
cout << "struct A: "
<< is_move_constructible<A>::value
<< endl;
cout << "struct B: "
<< is_move_constructible<B>::value
<< endl;
cout << "class C: "
<< is_move_constructible<C>::value
<< endl;
cout << "class D: "
<< is_move_constructible<D>::value
<< endl;
return 0;
}
|
Output:
char: true
struct A: true
struct B: true
class C: false
class D: false
Reference: http://www.cplusplus.com/reference/type_traits/is_move_constructible/
Share your thoughts in the comments
Please Login to comment...