ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
multicast.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/victimsnino/ReactivePlusPlus
9//
10
11#pragma once
12
13#include <rpp/operators/fwd.hpp>
14
15#include <rpp/observables/connectable_observable.hpp>
16
17namespace rpp::operators::details
18{
19 template<rpp::constraint::subject Subject>
21 {
22 RPP_NO_UNIQUE_ADDRESS Subject m_subject;
23
24 template<rpp::constraint::observable TObservable>
25 auto operator()(TObservable&& observable) const
26 {
27 static_assert(std::same_as<rpp::utils::extract_observable_type_t<TObservable>, rpp::subjects::utils::extract_subject_type_t<Subject>>, "observable and subject should be of same type");
28 return rpp::connectable_observable<std::decay_t<TObservable>, Subject>{std::forward<TObservable>(observable), m_subject};
29 }
30 };
31
32 template<template<typename> typename Subject>
34 {
35 template<rpp::constraint::observable TObservable>
36 auto operator()(TObservable&& observable) const
37 {
38 static_assert(rpp::constraint::subject<Subject<rpp::utils::extract_observable_type_t<TObservable>>>, "subject should be constructible with type of observable");
39
41 Subject<rpp::utils::extract_observable_type_t<TObservable>>>{std::forward<TObservable>(observable),
42 Subject<rpp::utils::extract_observable_type_t<TObservable>>{}};
43 }
44 };
45
46} // namespace rpp::operators::details
47
48namespace rpp::operators
49{
64 template<rpp::constraint::subject Subject>
65 auto multicast(Subject&& subject)
66 {
67 return details::multicast_t<std::decay_t<Subject>>{std::forward<Subject>(subject)};
68 }
69
84 template<template<typename> typename Subject>
89} // namespace rpp::operators
Extension over raw observable with ability to be manually connected at any time or ref_counting (shar...
Definition fwd.hpp:86
Base class for any observable used in RPP. It handles core callbacks of observable.
Definition observable.hpp:38
Definition fwd.hpp:47
auto multicast()
Converts ordinary observable to rpp::connectable_observable with help of inline instsantiated subject...
Definition multicast.hpp:85
Definition multicast.hpp:21