-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
003_rtti_std_is_move_constructible.cpp
34 lines (31 loc) · 1.32 KB
/
003_rtti_std_is_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
#include <iostream>
#include <type_traits>
struct Ex1 {
std::string str; // 成员拥有非平凡而不抛出的移动构造函数
};
struct Ex2 {
int n;
Ex2(Ex2&&) = default; // 平凡且不抛出
};
struct NoMove {
// 避免默认移动构造函数的隐式声明
// 然而,该类仍为可移动构造因为复制构造函数能绑定到右值参数
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';
}