| 18 | #include <memory> |
| 19 | |
| 20 | class copy_count_tracker |
| 21 | { |
| 22 | public: |
| 23 | copy_count_tracker() |
| 24 | : m_state(std::make_shared<state>()) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | copy_count_tracker(const copy_count_tracker& other) |
| 29 | : m_state{other.m_state} |
| 30 | { |
| 31 | ++m_state->copy_count; |
| 32 | } |
| 33 | |
| 34 | copy_count_tracker(copy_count_tracker&& other) noexcept |
| 35 | : m_state{other.m_state} // NOLINT(performance-move-constructor-init) |
| 36 | { |
| 37 | ++m_state->move_count; |
| 38 | } |
| 39 | |
| 40 | copy_count_tracker& operator=(const copy_count_tracker& other) |
| 41 | { |
| 42 | if (this == &other) |
| 43 | return *this; |
| 44 | m_state = other.m_state; |
| 45 | ++m_state->copy_count; |
| 46 | return *this; |
| 47 | } |
| 48 | |
| 49 | copy_count_tracker& operator=(copy_count_tracker&& other) noexcept |
| 50 | { |
| 51 | if (this == &other) |
| 52 | return *this; |
| 53 | m_state = other.m_state; |
| 54 | ++m_state->move_count; |
| 55 | return *this; |
| 56 | } |
| 57 | |
| 58 | bool operator==(const copy_count_tracker& other) const |
| 59 | { |
| 60 | return m_state == other.m_state; |
| 61 | } |
| 62 | |
| 63 | bool operator!=(const copy_count_tracker& other) const { return !(*this == other); } |
| 64 | |
| 65 | auto get_observable(size_t count = 1) |
| 66 | { |
| 67 | return rpp::source::create<copy_count_tracker>([this, count](const auto& sub) { |
| 68 | for (size_t i = 0; i < count && !sub.is_disposed(); ++i) |
| 69 | sub.on_next(*this); |
| 70 | sub.on_completed(); |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | auto get_observable_for_move(size_t count = 1) |
| 75 | { |
| 76 | return rpp::source::create<copy_count_tracker>([this, count](const auto& sub) { |
| 77 | for (size_t i = 0; i < count && !sub.is_disposed(); ++i) |
nothing calls this directly
no outgoing calls
no test coverage detected