ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
disposables_strategy.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// Distributed under the Boost Software License, Version 1.0.
5// (See accompanying file LICENSE_1_0.txt or copy at
6// https://www.boost.org/LICENSE_1_0.txt)
7//
8// Project home: https://github.com/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/observers/details/fwd.hpp>
14
15#include <rpp/defs.hpp>
16#include <rpp/disposables/disposable_wrapper.hpp>
17
18#include <atomic>
19
20namespace rpp::details::observers
21{
22 template<typename DisposableContainer>
23 class local_disposables_strategy
24 {
25 public:
26 local_disposables_strategy() = default;
27 local_disposables_strategy(local_disposables_strategy&& other) noexcept = default;
28
29 void add(const disposable_wrapper& d)
30 {
31 m_upstreams.push_back(d);
32 }
33
34 bool is_disposed() const noexcept
35 {
36 return m_is_disposed;
37 }
38
39 void dispose() const
40 {
41 m_is_disposed = true;
42 m_upstreams.dispose();
43 }
44
45 private:
46 RPP_NO_UNIQUE_ADDRESS DisposableContainer m_upstreams{};
47 mutable bool m_is_disposed{};
48 };
49
51 {
52 static constexpr void add(const rpp::disposable_wrapper&) {}
53
54 static constexpr bool is_disposed() noexcept { return false; }
55
56 static constexpr void dispose() {}
57 };
58} // namespace rpp::details::observers
disposable_wrapper_impl< interface_disposable > disposable_wrapper
Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition fwd.hpp:34
Definition disposables_strategy.hpp:51