std::is_move_assignable C++ with Examples
Last Updated :
12 Jun, 2020
The std::is_move_assignable template of C++ STL is present in the <type_traits> header file. The std::is_move_assignable template of C++ STL is used to check whether the T is a move assignable type(that can be assigned an rvalue reference of the same type) or not. 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
Parameters: The template std::is_move_assignable accepts a single parameter T(Trait class) to check whether T is move assignable or not.
Return Value: This template returns a boolean variable as shown below:
- True: If the type T is a move assignable type.
- False: If the type T is not a move assignable type.
Below is the program to illustrates the std::is_move_assignable template in C/C++:
Program:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct A {
};
struct B {
B& operator=(B&) = delete ;
};
struct C {
~C() = delete ;
};
int main()
{
cout << boolalpha;
cout << "int: "
<< is_move_assignable< int >::value
<< endl;
cout << "struct A: "
<< is_move_assignable<A>::value
<< endl;
cout << "struct B: "
<< is_move_assignable<B>::value
<< endl;
cout << "struct C: "
<< is_move_assignable<C>::value
<< endl;
unordered_multimap< int , string> m;
m.insert({ 1, "GfG" });
cout << "Map m: "
<< is_move_assignable< decltype (*m.begin())>::value;
return 0;
}
|
Output:
int: true
struct A: true
struct B: false
struct C: true
Map m: true
Reference: http://www.cplusplus.com/reference/type_traits/is_move_assignable/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...