ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
scan.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/details/member_overload.hpp>
14
15namespace rpp::details
16{
17struct scan_tag;
18}
19
20namespace rpp::details
21{
22// accepts Result and Type and returns Result
23template<typename Fn, typename Result, typename Type>
25
26template<constraint::decayed_type Type, constraint::decayed_type Result, scan_accumulator<Result, Type> AccumulatorFn>
27struct scan_impl;
28
29template<constraint::decayed_type Type, typename SpecificObservable>
30struct member_overload<Type, SpecificObservable, scan_tag>
31{
68 template<typename Result, scan_accumulator<Result, Type> AccumulatorFn>
69 auto scan(Result&& initial_value, AccumulatorFn&& accumulator) const & requires is_header_included<scan_tag, Result, AccumulatorFn>
70 {
71 return static_cast<const SpecificObservable*>(this)->template lift<std::decay_t<Result>>(scan_impl<Type, std::decay_t<Result>, std::decay_t<AccumulatorFn>>{std::forward<Result>(initial_value), std::forward<AccumulatorFn>(accumulator)});
72 }
73
74 template<typename Result, scan_accumulator<Result, Type> AccumulatorFn>
75 auto scan(Result&& initial_value, AccumulatorFn&& accumulator) && requires is_header_included<scan_tag, Result, AccumulatorFn>
76 {
77 return std::move(*static_cast<SpecificObservable*>(this)).template lift<std::decay_t<Result>>(scan_impl<Type, std::decay_t<Result>, std::decay_t<AccumulatorFn>>{std::forward<Result>(initial_value), std::forward<AccumulatorFn>(accumulator)});
78 }
79};
80} // namespace rpp::details
Definition: reduce.hpp:24
Definition: scan.hpp:24
Definition: member_overload.hpp:19
Definition: scan.hpp:41