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 };
30
31 namespace constraint
32 {
33 template<typename T>
34 concept disposables_strategy = requires(T& v, const T& const_v, const disposable_wrapper& d) {
35 v.add(d);
36 {
37 const_v.is_disposed()
38 } -> std::same_as<bool>;
39 const_v.dispose();
40 };
41 } // namespace constraint
42
43 template<typename DisposableContainer>
45
50
55
59 template<size_t Count>
61
62 using default_disposables_strategy = dynamic_disposables_strategy;
63
64 namespace details
65 {
66 template<disposables_mode mode>
67 consteval auto* deduce_optimal_disposables_strategy()
68 {
69 static_assert(mode == disposables_mode::Auto || mode == disposables_mode::None || mode == disposables_mode::External);
70
71 if constexpr (mode == disposables_mode::Auto)
72 return static_cast<default_disposables_strategy*>(nullptr);
73 else if constexpr (mode == disposables_mode::None)
74 return static_cast<none_disposables_strategy*>(nullptr);
75 else if constexpr (mode == disposables_mode::External)
76 return static_cast<composite_disposable_wrapper*>(nullptr);
77 else
78 return static_cast<void*>(nullptr);
79 }
80 } // namespace details
81
82 template<rpp::details::observers::disposables_mode Mode>
83 using deduce_optimal_disposables_strategy_t = std::remove_pointer_t<decltype(details::deduce_optimal_disposables_strategy<Mode>())>;
84} // 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