| 98 | }; |
| 99 | |
| 100 | class NonCopyable { |
| 101 | public: |
| 102 | NonCopyable(int a, int b) : value{new int(a * b)} { print_created(this, a, b); } |
| 103 | NonCopyable(NonCopyable &&o) noexcept : value{std::move(o.value)} { print_move_created(this); } |
| 104 | NonCopyable(const NonCopyable &) = delete; |
| 105 | NonCopyable() = delete; |
| 106 | void operator=(const NonCopyable &) = delete; |
| 107 | void operator=(NonCopyable &&) = delete; |
| 108 | std::string get_value() const { |
| 109 | if (value) { |
| 110 | return std::to_string(*value); |
| 111 | } |
| 112 | return "(null)"; |
| 113 | } |
| 114 | ~NonCopyable() { print_destroyed(this); } |
| 115 | |
| 116 | private: |
| 117 | std::unique_ptr<int> value; |
| 118 | }; |
| 119 | |
| 120 | // This is like the above, but is both copy and movable. In effect this means it should get moved |
| 121 | // when it is not referenced elsewhere, but copied if it is still referenced. |
no outgoing calls