ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
map.hpp
1
// ReactivePlusPlus library
2
//
3
// Copyright Aleksey Loginov 2023 - 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/AlexInLog/ReactivePlusPlus
9
//
10
11
#pragma once
12
13
#include <rpp/operators/fwd.hpp>
14
15
#include <rpp/defs.hpp>
16
#include <rpp/operators/details/strategy.hpp>
17
18
#include <type_traits>
19
20
namespace
rpp::operators::details
21
{
22
template
<rpp::constra
int
::observer TObserver, rpp::constra
int
::decayed_type Fn>
23
struct
map_observer_strategy
24
{
25
static
constexpr
auto
preferred_disposables_mode = rpp::details::observers::disposables_mode::None;
26
27
RPP_NO_UNIQUE_ADDRESS TObserver observer;
28
RPP_NO_UNIQUE_ADDRESS Fn fn;
29
30
template
<
typename
T>
31
void
on_next(T&& v)
const
32
{
33
observer.on_next(fn(std::forward<T>(v)));
34
}
35
36
void
on_error(
const
std::exception_ptr& err)
const
{ observer.on_error(err); }
37
38
void
on_completed()
const
{ observer.on_completed(); }
39
40
void
set_upstream(
const
disposable_wrapper
& d) { observer.set_upstream(d); }
41
42
bool
is_disposed()
const
{
return
observer.is_disposed(); }
43
};
44
45
template
<rpp::constra
int
::decayed_type Fn>
46
struct
map_t
: lift_operator<map_t<Fn>, Fn>
47
{
48
using
lift_operator<
map_t<Fn>
, Fn>::lift_operator;
49
50
template
<rpp::constra
int
::decayed_type T>
51
struct
operator_traits
52
{
53
static_assert
(!std::same_as<void, std::invoke_result_t<Fn, T>>,
"Fn is not invocable with T"
);
54
55
using
result_type = std::invoke_result_t<Fn, T>;
56
57
template
<rpp::constra
int
::observer_of_type<result_type> TObserver>
58
using
observer_strategy =
map_observer_strategy<TObserver, Fn>
;
59
};
60
61
template
<rpp::details::observables::constra
int
::disposables_strategy Prev>
62
using
updated_optimal_disposables_strategy = Prev;
63
};
64
}
// namespace rpp::operators::details
65
66
namespace
rpp::operators
67
{
94
* @see https://reactivex.io/documentation/operators/map.html
95
*/
96
template
<
typename
Fn>
97
requires
(!
utils::is_not_template_callable<Fn>
|| !std::same_as<void, std::invoke_result_t<Fn, rpp::utils::convertible_to_any>>)
98
auto
map
(Fn&& callable)
99
{
100
return
details::map_t<std::decay_t<Fn>
>{std::forward<Fn>(callable)};
101
}
102
}
// namespace rpp::operators
rpp::utils::is_not_template_callable
Definition
function_traits.hpp:45
rpp::disposable_wrapper
disposable_wrapper_impl< interface_disposable > disposable_wrapper
Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition
fwd.hpp:34
rpp::operators::map
auto map(Fn &&callable)
Transforms the items emitted by an Observable via applying a function to each item and emitting resul...
Definition
map.hpp:94
rpp::operators::details::map_observer_strategy
Definition
map.hpp:24
rpp::operators::details::map_t::operator_traits
Definition
map.hpp:52
rpp::operators::details::map_t
Definition
map.hpp:47
src
rpp
rpp
operators
map.hpp
Generated by
1.17.0