ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
take_while.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/defs.hpp>
14#include <rpp/operators/lift.hpp> // required due to operator uses lift
15#include <rpp/operators/fwd/take_while.hpp>
16#include <rpp/subscribers/constraints.hpp>
17#include <rpp/utils/utilities.hpp>
18
19
20IMPLEMENTATION_FILE(take_while_tag);
21
22namespace rpp::details
23{
24template<constraint::decayed_type Type, std::predicate<const Type&> Predicate>
26{
27 RPP_NO_UNIQUE_ADDRESS Predicate predicate;
28
29 template<typename TVal, constraint::subscriber_of_type<Type> TSub>
30 void operator()(TVal&& value, const TSub& subscriber) const
31 {
32 if (predicate(utils::as_const(value)))
33 subscriber.on_next(std::forward<TVal>(value));
34 else
35 subscriber.on_completed();
36 }
37};
38
39template<constraint::decayed_type Type, std::predicate<const Type&> Predicate>
41{
42 RPP_NO_UNIQUE_ADDRESS take_while_impl_on_next<Type, Predicate> on_next;
43
44 template<constraint::subscriber TSub>
45 auto operator()(TSub&& subscriber) const
46 {
47 auto subscription = subscriber.get_subscription();
48 return create_subscriber_with_state<Type>(std::move(subscription),
49 on_next,
50 utils::forwarding_on_error{},
51 utils::forwarding_on_completed{},
52 std::forward<TSub>(subscriber));
53 }
54};
55} // namespace rpp::details
Definition: take_while.hpp:26
Definition: take_while.hpp:41