MCPcopy Create free account
hub / github.com/andreiavrammsd/cpp-channel / data

Class data

examples/move.cpp:8–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6#include <vector>
7
8class data final {
9 public:
10 static std::size_t copies_;
11 static std::size_t moves_;
12
13 data() = default;
14 explicit data(int value) : value_{value} {}
15
16 int get_value() const { return value_; }
17
18 data(const data& other) noexcept : value_{other.value_}
19 {
20 std::cout << "copy " << value_ << '\n';
21 ++copies_;
22 }
23
24 data& operator=(const data& other)
25 {
26 if (this != &other) {
27 value_ = other.value_;
28 std::cout << "copy " << value_ << '\n';
29 ++copies_;
30 }
31
32 return *this;
33 }
34
35 data(data&& other) noexcept : value_{other.value_}
36 {
37 std::cout << "move " << value_ << '\n';
38 ++moves_;
39 }
40
41 data& operator=(data&& other) noexcept
42 {
43 if (this != &other) {
44 value_ = other.value_;
45 std::cout << "move " << value_ << '\n';
46 ++moves_;
47 }
48
49 return *this;
50 }
51
52 ~data() = default;
53
54 private:
55 int value_{};
56};
57
58std::size_t data::copies_{};
59std::size_t data::moves_{};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected