ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
merge.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/observables/constraints.hpp>
14#include <rpp/observables/details/member_overload.hpp>
15
16namespace rpp::details
17{
18struct merge_tag;
19}
20
21namespace rpp::details
22{
23template<constraint::decayed_type Type>
24struct merge_impl;
25
26template<constraint::decayed_type Type, constraint::observable_of_type<Type> ... TObservables>
27auto merge_with_impl(TObservables&&... observables);
28
29template<constraint::decayed_type Type, typename SpecificObservable>
30struct member_overload<Type, SpecificObservable, merge_tag>
31{
71 template<typename ...Args>
72 auto merge() const& requires (is_header_included<merge_tag, Args...> && rpp::constraint::observable<Type>)
73 {
74 return static_cast<const SpecificObservable*>(this)->template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>{});
75 }
76
77 template<typename ...Args>
78 auto merge() && requires (is_header_included<merge_tag, Args...>&& rpp::constraint::observable<Type>)
79 {
80 return std::move(*static_cast<SpecificObservable*>(this)).template lift<utils::extract_observable_type_t<Type>>(merge_impl<Type>{});
81 }
82
118 template<constraint::observable_of_type<Type> ...TObservables>
119 auto merge_with(TObservables&&... observables) const& requires (is_header_included<merge_tag, TObservables...>&& sizeof...(TObservables) >= 1)
120 {
121 return merge_with_impl<Type>(static_cast<const SpecificObservable*>(this)->as_dynamic(), std::forward<TObservables>(observables).as_dynamic()...);
122 }
123
124 template<constraint::observable_of_type<Type> ...TObservables>
125 auto merge_with(TObservables&&... observables) && requires (is_header_included<merge_tag, TObservables...> && sizeof...(TObservables) >= 1)
126 {
127 return merge_with_impl<Type>(std::move(*static_cast<SpecificObservable*>(this)).as_dynamic(), std::forward<TObservables>(observables).as_dynamic()...);
128 }
129};
130} // namespace rpp::details
Definition: constraints.hpp:19
Definition: member_overload.hpp:19
Definition: merge.hpp:80