ReactivePlusPlus
ReactiveX implementation for C++20
Toggle main menu visibility
Loading...
Searching...
No Matches
defer.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
#pragma once
11
12
#include <rpp/sources/fwd.hpp>
13
14
#include <rpp/defs.hpp>
15
#include <rpp/observables/observable.hpp>
16
17
namespace
rpp::details
18
{
19
template
<
typename
Factory>
20
struct
defer_strategy
21
{
22
using
value_type = rpp::utils::extract_observable_type_t<std::invoke_result_t<Factory>>;
23
using
optimal_disposables_strategy =
typename
std::invoke_result_t<Factory>::optimal_disposables_strategy;
24
25
RPP_NO_UNIQUE_ADDRESS Factory observable_factory;
26
27
template
<rpp::constra
int
::observer_of_type<value_type> TObs>
28
void
subscribe(TObs&& obs)
const
29
{
30
observable_factory().subscribe(std::forward<TObs>(obs));
31
}
32
};
33
}
// namespace rpp::details
34
35
namespace
rpp
36
{
37
template
<constra
int
::decayed_type Type,
typename
Factory>
38
using
defer_observable =
observable<Type, details::defer_strategy<Factory>
>;
39
}
// namespace rpp
40
41
namespace
rpp::source
42
{
43
55
template
<std::invocable Factory>
56
requires
rpp::constraint::observable<std::invoke_result_t<Factory>
>
57
auto
defer
(Factory&& observable_factory)
58
{
59
return
defer_observable<rpp::utils::extract_observable_type_t<std::invoke_result_t<Factory>>, Factory>{std::forward<Factory>(observable_factory)};
60
}
61
}
// namespace rpp::source
rpp::observable
Base class for any observable used in RPP. It handles core callbacks of observable.
Definition
observable.hpp:38
rpp::constraint::observable
Definition
fwd.hpp:80
rpp::source::defer
auto defer(Factory &&observable_factory)
Creates rpp::observable that calls the specified observable factory to create an observable for each ...
Definition
defer.hpp:57
rpp::details::defer_strategy
Definition
defer.hpp:21
src
rpp
rpp
sources
defer.hpp
Generated by
1.17.0