ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
interface_observable.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/defs.hpp> // RPP_EMPTY_BASES
14#include <rpp/observables/blocking_observable.hpp> // as_blocking
15#include <rpp/observables/constraints.hpp> // own constraints
16#include <rpp/observables/fwd.hpp> // own forwarding
17#include <rpp/operators/fwd.hpp> // forwarding of member_overaloads
18#include <rpp/utils/function_traits.hpp> // decayed_invoke_result_t
19
20#include <type_traits>
21
22namespace rpp::details
23{
24template<typename T, typename TObservable>
26} // namespace rpp::details
27
28namespace rpp
29{
35template<constraint::decayed_type Type, typename SpecificObservable>
36struct RPP_EMPTY_BASES interface_observable
38 , details::member_overload<Type, SpecificObservable, details::buffer_tag>
39 , details::member_overload<Type, SpecificObservable, details::combine_latest_tag>
40 , details::member_overload<Type, SpecificObservable, details::concat_tag>
41 , details::member_overload<Type, SpecificObservable, details::delay_tag>
42 , details::member_overload<Type, SpecificObservable, details::debounce_tag>
43 , details::member_overload<Type, SpecificObservable, details::distinct_until_changed_tag>
44 , details::member_overload<Type, SpecificObservable, details::do_tag>
45 , details::member_overload<Type, SpecificObservable, details::filter_tag>
46 , details::member_overload<Type, SpecificObservable, details::first_tag>
47 , details::member_overload<Type, SpecificObservable, details::flat_map_tag>
48 , details::member_overload<Type, SpecificObservable, details::group_by_tag>
49 , details::member_overload<Type, SpecificObservable, details::last_tag>
50 , details::member_overload<Type, SpecificObservable, details::lift_tag>
51 , details::member_overload<Type, SpecificObservable, details::map_tag>
52 , details::member_overload<Type, SpecificObservable, details::merge_tag>
53 , details::member_overload<Type, SpecificObservable, details::multicast_tag>
54 , details::member_overload<Type, SpecificObservable, details::observe_on_tag>
55 , details::member_overload<Type, SpecificObservable, details::on_error_resume_next_tag>
56 , details::member_overload<Type, SpecificObservable, details::publish_tag>
57 , details::member_overload<Type, SpecificObservable, details::reduce_tag>
58 , details::member_overload<Type, SpecificObservable, details::repeat_tag>
59 , details::member_overload<Type, SpecificObservable, details::sample_tag>
60 , details::member_overload<Type, SpecificObservable, details::scan_tag>
61 , details::member_overload<Type, SpecificObservable, details::skip_tag>
62 , details::member_overload<Type, SpecificObservable, details::start_with_tag>
63 , details::member_overload<Type, SpecificObservable, details::subscribe_on_tag>
64 , details::member_overload<Type, SpecificObservable, details::subscribe_tag>
65 , details::member_overload<Type, SpecificObservable, details::switch_map_tag>
66 , details::member_overload<Type, SpecificObservable, details::switch_on_next_tag>
67 , details::member_overload<Type, SpecificObservable, details::take_last_tag>
68 , details::member_overload<Type, SpecificObservable, details::take_tag>
69 , details::member_overload<Type, SpecificObservable, details::take_until_tag>
70 , details::member_overload<Type, SpecificObservable, details::take_while_tag>
71 , details::member_overload<Type, SpecificObservable, details::timeout_tag>
72 , details::member_overload<Type, SpecificObservable, details::window_tag>
73 , details::member_overload<Type, SpecificObservable, details::with_latest_from_tag>
74{
75public:
76
84 template<details::op_fn<SpecificObservable> OperatorFn>
85 auto op(OperatorFn&& fn) const &
86 {
87 return fn(CastThis());
88 }
89
90 template<details::op_fn<SpecificObservable> OperatorFn>
91 auto op(OperatorFn&& fn) &&
92 {
93 return fn(MoveThis());
94 }
95
99 auto as_blocking() const &
100 {
101 return blocking_observable{ CastThis ()};
102 }
103
104 auto as_blocking()&&
105 {
106 return blocking_observable{ MoveThis() };
107 }
108
109private:
110 const SpecificObservable& CastThis() const
111 {
112 return *static_cast<const SpecificObservable*>(this);
113 }
114
115 SpecificObservable&& MoveThis()
116 {
117 return std::move(*static_cast<SpecificObservable*>(this));
118 }
119};
120} // namespace rpp
blocking alternative of observable: provides interface where each function do blocking subscribe on o...
Definition: blocking_observable.hpp:34
Definition: constraints.hpp:19
Definition: interface_observable.hpp:25
auto op(OperatorFn &&fn) const &
The apply function to observable which returns observable of another type.
Definition: interface_observable.hpp:85
Definition: member_overload.hpp:19
Base part of observable. Mostly used to provide some interface functions used by all observables.
Definition: interface_observable.hpp:74
auto as_blocking() const &
Converts existing observable to rpp::blocking_observable which has another interface and abilities.
Definition: interface_observable.hpp:99