-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy path010_concepts_move_constructible.cpp
35 lines (32 loc) · 1.37 KB
/
010_concepts_move_constructible.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <type_traits>
struct Ex1 {
std::string str; // member has a non-trivial but non-throwing move ctor
};
struct Ex2 {
int n;
Ex2(Ex2&&) = default; // trivial and non-throwing
};
struct NoMove {
// prevents implicit declaration of default move constructor
// however, the class is still move-constructible because its
// copy constructor can bind to an rvalue argument
NoMove(const NoMove&) {}
};
int main() {
std::cout << std::boolalpha << "Ex1 is move-constructible? "
<< std::is_move_constructible<Ex1>::value << '\n'
<< "Ex1 is trivially move-constructible? "
<< std::is_trivially_move_constructible<Ex1>::value << '\n'
<< "Ex1 is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<Ex1>::value << '\n'
<< "Ex2 is trivially move-constructible? "
<< std::is_trivially_move_constructible<Ex2>::value << '\n'
<< "Ex2 is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<Ex2>::value << '\n';
std::cout << std::boolalpha
<< "NoMove is move-constructible? "
<< std::is_move_constructible<NoMove>::value << '\n'
<< "NoMove is nothrow move-constructible? "
<< std::is_nothrow_move_constructible<NoMove>::value << '\n';
}