ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
delay.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2022 - present.
4// TC Wang 2022 - present.
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// https://www.boost.org/LICENSE_1_0.txt)
8//
9// Project home: https://github.com/victimsnino/ReactivePlusPlus
10
11#pragma once
12
13#include <rpp/schedulers/constraints.hpp> // schedulers::constraint::scheduler
14#include <rpp/observables/details/member_overload.hpp> // member_overload
15
16namespace rpp::details
17{
18struct delay_tag;
19}
20
21namespace rpp::details
22{
23template<constraint::decayed_type Type, schedulers::constraint::scheduler TScheduler>
24struct delay_impl;
25
26template<constraint::decayed_type Type, typename SpecificObservable>
27struct member_overload<Type, SpecificObservable, delay_tag>
28{
29
63 template<schedulers::constraint::scheduler TScheduler>
64 auto delay(auto&& delay_duration,
65 TScheduler&& scheduler) const& requires is_header_included<delay_tag, TScheduler>
66 {
67 return cast_this()->template lift<Type>(
68 delay_impl<Type, std::decay_t<TScheduler>>{std::forward<TScheduler>(scheduler),
69 std::chrono::duration_cast<rpp::schedulers::duration>(delay_duration)});
70 }
71
72 template<schedulers::constraint::scheduler TScheduler>
73 auto delay(auto&& delay_duration,
74 TScheduler&& scheduler) && requires is_header_included<delay_tag, TScheduler>
75 {
76 return move_this().template lift<Type>(
77 delay_impl<Type, std::decay_t<TScheduler>>{std::forward<TScheduler>(scheduler),
78 std::chrono::duration_cast<rpp::schedulers::duration>(delay_duration)});
79 }
80
81private:
82 const SpecificObservable* cast_this() const
83 {
84 return static_cast<const SpecificObservable*>(this);
85 }
86
87 SpecificObservable&& move_this()
88 {
89 return std::move(*static_cast<SpecificObservable*>(this));
90 }
91};
92
93} // namespace rpp::details
Definition: delay.hpp:153
Definition: member_overload.hpp:19