ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
fwd.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/disposables/fwd.hpp>
14
15#include <rpp/disposables/details/container.hpp>
16
17#include <type_traits>
18
19namespace rpp::details::observers
20{
21 enum class disposables_mode : uint8_t
22 {
23 // Let observer deduce disposables mode
24 Auto = 0,
25 // No any disposables logic for observer expected
26 None = 1,
27 // Use external (passed to constructor) composite_disposable_wrapper as disposable
28 External = 2,
29 // Observer just controls is_disposed or not but upstreams handled via observer_strategy
30 Boolean = 3
31 };
32
33 namespace constraint
34 {
35 template<typename T>
36 concept disposables_strategy = requires(T& v, const T& const_v, const disposable_wrapper& d) {
37 v.add(d);
38 {
39 const_v.is_disposed()
40 } -> std::same_as<bool>;
41 const_v.dispose();
42 };
43 } // namespace constraint
44
45 template<typename DisposableContainer>
47
56
61
65 template<size_t Count>
67
68 using default_disposables_strategy = dynamic_disposables_strategy;
69
70 namespace details
71 {
72 template<disposables_mode mode>
73 consteval auto* deduce_optimal_disposables_strategy()
74 {
75 static_assert(mode == disposables_mode::Auto || mode == disposables_mode::None || mode == disposables_mode::External || mode == disposables_mode::Boolean);
76
77#if defined(RPP_DISABLE_DISPOSABLES_OPTIMIZATION) and RPP_DISABLE_DISPOSABLES_OPTIMIZATION
78 if constexpr (mode == disposables_mode::External)
79 return static_cast<composite_disposable_wrapper*>(nullptr);
80 else
81 return static_cast<default_disposables_strategy*>(nullptr);
82#else
83 if constexpr (mode == disposables_mode::Auto)
84 return static_cast<default_disposables_strategy*>(nullptr);
85 else if constexpr (mode == disposables_mode::None)
86 return static_cast<none_disposables_strategy*>(nullptr);
87 else if constexpr (mode == disposables_mode::External)
88 return static_cast<composite_disposable_wrapper*>(nullptr);
89 else if constexpr (mode == disposables_mode::Boolean)
90 return static_cast<boolean_disposables_strategy*>(nullptr);
91 else
92 return static_cast<void*>(nullptr);
93#endif
94 }
95 } // namespace details
96
97 template<rpp::details::observers::disposables_mode Mode>
98 using deduce_optimal_disposables_strategy_t = std::remove_pointer_t<decltype(details::deduce_optimal_disposables_strategy<Mode>())>;
99} // namespace rpp::details::observers
Definition disposables_strategy.hpp:60
Definition disposables_strategy.hpp:24
disposable_wrapper_impl< interface_composite_disposable > composite_disposable_wrapper
Wrapper to keep "composite" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition fwd.hpp:41
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