ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
with_latest_from.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#pragma once
11
12#include <rpp/observables/details/member_overload.hpp>
13#include <rpp/observables/constraints.hpp>
14#include <rpp/utils/functors.hpp>
15#include <rpp/utils/function_traits.hpp>
16
17
18#include <tuple>
19
20namespace rpp::details
21{
22struct with_latest_from_tag;
23}
24
25namespace rpp::details
26{
27template<constraint::decayed_type Type, typename TSelector, constraint::observable ...TObservables>
28struct with_latest_from_impl;
29
30template<constraint::decayed_type Type, typename SpecificObservable>
31struct member_overload<Type, SpecificObservable, with_latest_from_tag>
32{
70 template<constraint::observable ...TObservables, std::invocable<Type, utils::extract_observable_type_t<TObservables>...> TSelector>
71 auto with_latest_from(TSelector&& selector, TObservables&&...observables) const& requires is_header_included<with_latest_from_tag, TObservables...>
72 {
73 return static_cast<const SpecificObservable*>(this)->template lift<utils::decayed_invoke_result_t<TSelector, Type, utils::extract_observable_type_t<TObservables>...>>(with_latest_from_impl<Type, std::decay_t<TSelector>, std::decay_t<TObservables>...>{std::forward<TSelector>(selector), { std::forward<TObservables>(observables)... }});
74 }
75
76 template<constraint::observable ...TObservables, std::invocable<Type, utils::extract_observable_type_t<TObservables>...> TSelector>
77 auto with_latest_from(TSelector&& selector, TObservables&&...observables) && requires is_header_included<with_latest_from_tag, TObservables...>
78 {
79 return std::move(*static_cast<SpecificObservable*>(this)).template lift<utils::decayed_invoke_result_t<TSelector, Type, utils::extract_observable_type_t<TObservables>...>>(with_latest_from_impl<Type, std::decay_t<TSelector>, std::decay_t<TObservables>...>{std::forward<TSelector>(selector), { std::forward<TObservables>(observables)... }});
80 }
81
102 template<constraint::observable ...TObservables>
103 auto with_latest_from(TObservables&&...observables) const& requires is_header_included<with_latest_from_tag, TObservables...>
104 {
105 return static_cast<const SpecificObservable*>(this)->with_latest_from(utils::pack_to_tuple{}, std::forward<TObservables>(observables)...);
106 }
107
108 template<constraint::observable ...TObservables>
109 auto with_latest_from(TObservables&&...observables) && requires is_header_included<with_latest_from_tag, TObservables...>
110 {
111 return std::move(*static_cast<SpecificObservable*>(this)).with_latest_from(utils::pack_to_tuple{}, std::forward<TObservables>(observables)...);
112 }
113};
114} // namespace rpp::details
Definition: constraints.hpp:19
Definition: member_overload.hpp:19
Definition: with_latest_from.hpp:119