ReactivePlusPlus
One more implementation of ReactiveX approach in C++ with care about performance and templates in mind
 
Loading...
Searching...
No Matches
take.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 take_tag;
18}
19
20namespace rpp::details
21{
22template<constraint::decayed_type Type>
23struct take_impl;
24
25template<constraint::decayed_type Type, typename SpecificObservable>
26struct member_overload<Type, SpecificObservable, take_tag>
27{
60 template<typename...Args>
61 auto take(size_t count) const & requires is_header_included<take_tag, Args...>
62 {
63 return cast_this()->template lift<Type>(take_impl<Type>{count});
64 }
65
66 template<typename...Args>
67 auto take(size_t count) && requires is_header_included<take_tag, Args...>
68 {
69 return move_this().template lift<Type>(take_impl<Type>{count});
70 }
71
72private:
73 const SpecificObservable* cast_this() const
74 {
75 return static_cast<const SpecificObservable*>(this);
76 }
77
78 SpecificObservable&& move_this()
79 {
80 return std::move(*static_cast<SpecificObservable*>(this));
81 }
82};
83} // namespace rpp::details
Definition: member_overload.hpp:19
Definition: take.hpp:45