ReactivePlusPlus
ReactiveX implementation for C++20
Loading...
Searching...
No Matches
callback_disposable.hpp
1// ReactivePlusPlus library
2//
3// Copyright Aleksey Loginov 2023 - 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/disposables/fwd.hpp>
14
15#include <rpp/disposables/details/base_disposable.hpp>
16#include <rpp/disposables/disposable_wrapper.hpp>
17
18namespace rpp
19{
25 template<rpp::constraint::is_nothrow_invocable Fn>
26 class callback_disposable final : public details::base_disposable
27 {
28 public:
29 explicit callback_disposable(Fn&& fn)
30 : m_fn{std::move(fn)}
31 {
32 }
33
34 explicit callback_disposable(const Fn& fn)
35 : m_fn{fn}
36 {
37 }
38
39 private:
40 void base_dispose_impl(interface_disposable::Mode) noexcept override { std::move(m_fn)(); } // NOLINT(bugprone-exception-escape)
41
42 private:
43 RPP_NO_UNIQUE_ADDRESS Fn m_fn;
44 };
45
46 template<rpp::constraint::is_nothrow_invocable Fn>
47 disposable_wrapper make_callback_disposable(Fn&& invocable)
48 {
50 }
51} // namespace rpp
static disposable_wrapper_impl make(TArgs &&... args)
Definition disposable_wrapper.hpp:164
disposable_wrapper_impl< interface_disposable > disposable_wrapper
Wrapper to keep "simple" disposable. Specialization of rpp::disposable_wrapper_impl.
Definition fwd.hpp:34