|
| 1 | +// include/beman/execution/detail/inline_scheduler.hpp -*-C++-*- |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#ifndef INCLUDED_BEMAN_DETAIL_EXECUTION_INLINE_SCHEDULER |
| 5 | +#define INCLUDED_BEMAN_DETAIL_EXECUTION_INLINE_SCHEDULER |
| 6 | + |
| 7 | +// ---------------------------------------------------------------------------- |
| 8 | +#include <beman/execution/detail/common.hpp> |
| 9 | +#ifdef BEMAN_HAS_IMPORT_STD |
| 10 | +import std; |
| 11 | +#else |
| 12 | +#include <type_traits> |
| 13 | +#include <utility> |
| 14 | +#endif |
| 15 | +#ifdef BEMAN_HAS_MODULES |
| 16 | +import beman.execution.detail.get_completion_scheduler; |
| 17 | +import beman.execution.detail.sender; |
| 18 | +import beman.execution.detail.receiver; |
| 19 | +import beman.execution.detail.set_value; |
| 20 | +import beman.execution.detail.operation_state; |
| 21 | +import beman.execution.detail.scheduler; |
| 22 | +import beman.execution.detail.scheduler_t; |
| 23 | +import beman.execution.detail.completion_signatures; |
| 24 | +#else |
| 25 | +#include <beman/execution/detail/get_completion_scheduler.hpp> |
| 26 | +#include <beman/execution/detail/sender.hpp> |
| 27 | +#include <beman/execution/detail/receiver.hpp> |
| 28 | +#include <beman/execution/detail/set_value.hpp> |
| 29 | +#include <beman/execution/detail/operation_state.hpp> |
| 30 | +#include <beman/execution/detail/scheduler.hpp> |
| 31 | +#include <beman/execution/detail/completion_signatures.hpp> |
| 32 | +#endif |
| 33 | + |
| 34 | +namespace beman::execution { |
| 35 | +struct inline_scheduler { |
| 36 | + using scheduler_concept = ::beman::execution::scheduler_t; |
| 37 | + |
| 38 | + struct env { |
| 39 | + static auto |
| 40 | + query(const ::beman::execution::get_completion_scheduler_t<::beman::execution::set_value_t>&) noexcept |
| 41 | + -> inline_scheduler { |
| 42 | + return {}; |
| 43 | + } |
| 44 | + }; |
| 45 | + |
| 46 | + template <::beman::execution::receiver Rcvr> |
| 47 | + struct state { |
| 48 | + using operation_state_concept = ::beman::execution::operation_state_t; |
| 49 | + ::std::remove_cvref_t<Rcvr> rcvr; |
| 50 | + auto start() & noexcept -> void { ::beman::execution::set_value(::std::move(rcvr)); } |
| 51 | + }; |
| 52 | + |
| 53 | + struct sender { |
| 54 | + using sender_concept = ::beman::execution::sender_t; |
| 55 | + using completion_signatures = ::beman::execution::completion_signatures<::beman::execution::set_value_t()>; |
| 56 | + |
| 57 | + static constexpr auto get_env() noexcept -> env { return {}; } |
| 58 | + |
| 59 | + template <typename, typename...> |
| 60 | + static consteval auto get_completion_signatures() noexcept -> completion_signatures { |
| 61 | + return {}; |
| 62 | + } |
| 63 | + |
| 64 | + template <::beman::execution::receiver Rcvr> |
| 65 | + auto connect(Rcvr&& receiver) noexcept(::std::is_nothrow_constructible_v<::std::remove_cvref_t<Rcvr>, Rcvr>) |
| 66 | + -> state<Rcvr> { |
| 67 | + return {::std::forward<Rcvr>(receiver)}; |
| 68 | + } |
| 69 | + }; |
| 70 | + |
| 71 | + static constexpr auto schedule() noexcept -> sender { return {}; } |
| 72 | + |
| 73 | + auto operator==(const inline_scheduler&) const -> bool = default; |
| 74 | +}; |
| 75 | +} // namespace beman::execution |
| 76 | + |
| 77 | +// ---------------------------------------------------------------------------- |
| 78 | + |
| 79 | +#endif // INCLUDED_BEMAN_DETAIL_EXECUTION_INLINE_SCHEDULER |
0 commit comments