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