ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
do.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/operators/lift.hpp> // required due to operator uses lift
14#include <rpp/operators/fwd/do.hpp> // own forwarding
15#include <rpp/operators/details/subscriber_with_state.hpp> // create_subscriber_with_state
16#include <rpp/subscribers/constraints.hpp> // constraint::subscriber_of_type
17#include <rpp/utils/utilities.hpp> // utils::as_const
18
19IMPLEMENTATION_FILE(do_tag);
20
21namespace rpp::details
22{
23template<constraint::decayed_type Type, constraint::observer_of_type<Type> TObs>
24struct do_impl
25{
26 TObs observer;
27
28 template<constraint::subscriber_of_type<Type> TSub>
29 auto operator()(TSub&& subscriber) const
30 {
31 auto subscription = subscriber.get_subscription();
32
33 return create_subscriber_with_state<Type>(std::move(subscription),
34 [](auto&& value, const TSub& subscriber, const TObs& do_observer)
35 {
36 do_observer.on_next(utils::as_const(value));
37 subscriber.on_next(std::forward<decltype(value)>(value));
38 },
39 [](const std::exception_ptr& err,
40 const TSub& subscriber,
41 const TObs& do_observer)
42 {
43 do_observer.on_error(err);
44 subscriber.on_error(err);
45 },
46 [](const TSub& subscriber, const TObs& do_observer)
47 {
48 do_observer.on_completed();
49 subscriber.on_completed();
50 },
51 std::forward<TSub>(subscriber),
52 observer);
53 }
54};
55} // namespace rpp::details
Definition: do.hpp:25