ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
map.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_NO_UNIQUE_ADDRESS
14#include <rpp/operators/lift.hpp> // required due to operator uses lift
15#include <rpp/operators/fwd/map.hpp> // own forwarding
16#include <rpp/subscribers/constraints.hpp> // constraint::subscriber_of_type
17#include <rpp/utils/function_traits.hpp> // decayed_invoke_result_t
18#include <rpp/utils/utilities.hpp> // as_counst
19
20#include <utility>
21
22IMPLEMENTATION_FILE(map_tag);
23
24namespace rpp::details
25{
26template<constraint::decayed_type Type, std::invocable<Type> Callable>
28{
29 RPP_NO_UNIQUE_ADDRESS Callable callable;
30
31 template<typename TVal, constraint::subscriber_of_type<utils::decayed_invoke_result_t<Callable, Type>> TSub>
32 void operator()(TVal&& value, const TSub& subscriber) const
33 {
34 subscriber.on_next(callable(utils::as_const(std::forward<TVal>(value))));
35 }
36};
37
38template<constraint::decayed_type Type, std::invocable<Type> Callable>
40{
41 RPP_NO_UNIQUE_ADDRESS map_impl_on_next<Type, Callable> on_next;
42
43 template<constraint::subscriber TSub>
44 auto operator()(TSub&& subscriber) const
45 {
46 auto subscription = subscriber.get_subscription();
47 return create_subscriber_with_state<Type>(std::move(subscription),
48 on_next,
49 utils::forwarding_on_error{},
50 utils::forwarding_on_completed{},
51 std::forward<TSub>(subscriber));
52 }
53};
54} // namespace rpp::details
Definition: map.hpp:28
Definition: map.hpp:40