-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathmove.cpp
58 lines (43 loc) · 1.04 KB
/
move.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include "msd/channel.hpp"
class Data final {
int i_{};
public:
Data() = default;
explicit Data(int i) : i_{i} {}
int getI() const { return i_; }
Data(const Data& other) noexcept : i_{other.i_} { std::cout << "copy " << i_ << '\n'; }
Data& operator=(const Data& other)
{
if (this != &other) {
i_ = other.i_;
}
std::cout << "copy " << i_ << '\n';
return *this;
}
Data(Data&& other) noexcept : i_{other.i_} { std::cout << "move " << i_ << '\n'; }
Data& operator=(Data&& other) noexcept
{
if (this != &other) {
i_ = other.i_;
std::cout << "move " << i_ << '\n';
}
return *this;
}
~Data() = default;
};
int main()
{
msd::channel<Data> ch{10};
auto in1 = Data{1};
ch << in1;
ch << Data{2};
auto in3 = Data{3};
ch << std::move(in3);
for (auto out : ch) {
std::cout << out.getI() << '\n';
if (ch.empty()) {
break;
}
}
}