ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
skip.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/operators/lift.hpp> // required due to operator uses lift
14#include <rpp/operators/details/subscriber_with_state.hpp> // create_subscriber_with_state
15#include <rpp/operators/fwd/skip.hpp> // own forwarding
16#include <rpp/subscribers/constraints.hpp> // constraint::subscriber
17#include <rpp/utils/functors.hpp> // forwarding_on_error
18
19IMPLEMENTATION_FILE(skip_tag);
20
21namespace rpp::details
22{
24{
25 mutable size_t count;
26};
27
29{
30 void operator()(auto&& value, const constraint::subscriber auto& subscriber, const skip_state& state) const
31 {
32 if (state.count == 0)
33 subscriber.on_next(std::forward<decltype(value)>(value));
34 else
35 --state.count;
36 }
37};
38
39template<constraint::decayed_type Type>
41{
42 size_t count;
43
44 template<constraint::subscriber_of_type<Type> TSub>
45 auto operator()(TSub&& subscriber) const
46 {
47 auto subscription = subscriber.get_subscription();
48 // dynamic_state there to make shared_ptr for observer instead of making shared_ptr for state
49 return create_subscriber_with_dynamic_state<Type>(std::move(subscription),
51 utils::forwarding_on_error{},
52 utils::forwarding_on_completed{},
53 std::forward<TSub>(subscriber),
54 skip_state{count});
55 }
56};
57} // namespace rpp::details
Definition: constraints.hpp:19
Definition: skip.hpp:41
Definition: skip.hpp:29
Definition: skip.hpp:24