-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp11_move_semantics.cpp
More file actions
59 lines (45 loc) · 1.56 KB
/
cpp11_move_semantics.cpp
File metadata and controls
59 lines (45 loc) · 1.56 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
auto PrintLine = []() { std::cout << "\n=========================================\n\n"; };
struct Example {
public:
// Constructor
Example(int i = 0) { std::cout << "Constructor \t\t : " << __PRETTY_FUNCTION__ << "\n"; }
// Destructor
~Example() { std::cout << "Destructor \t\t : " << __PRETTY_FUNCTION__ << "\n"; }
// Copy Constructor
Example(const Example& that) { std::cout << "Copy Constructor \t : " << __PRETTY_FUNCTION__ << "\n"; }
// Move Constructor
Example(const Example&& that) { std::cout << "Move Constructor \t : " << __PRETTY_FUNCTION__ << "\n"; }
// Copy Assignment operator
Example& operator=(const Example& that) { std::cout << "Copy Assignment \t : " << __PRETTY_FUNCTION__ << "\n"; }
// Move Assignment operator
Example operator=(const Example&& that) { std::cout << "Move Assignment \t : " << __PRETTY_FUNCTION__ << "\n"; }
};
//void FunctionTakingExample(Example e) { std::cout << __PRETTY_FUNCTION__ << "\n"; }
void FunctionTakingExample(Example& e) { std::cout << __PRETTY_FUNCTION__ << "\n"; }
void FunctionTakingExample(Example&& e) { std::cout << __PRETTY_FUNCTION__ << "\n"; }
int main() {
PrintLine();
{
FunctionTakingExample(Example());
}
PrintLine();
PrintLine();
{
Example e;
FunctionTakingExample(e);
}
PrintLine();
PrintLine();
{
Example e;
FunctionTakingExample(std::move(e));
}
PrintLine();
PrintLine();
{
FunctionTakingExample(10);
}
PrintLine();
return 0;
}