|
| 1 | +// include/beman/execution26/detail/just.hpp -*-C++-*- |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_JUST |
| 5 | +#define INCLUDED_BEMAN_EXECUTION26_DETAIL_JUST |
| 6 | + |
| 7 | +#include <beman/execution26/detail/set_error.hpp> |
| 8 | +#include <beman/execution26/detail/set_stopped.hpp> |
| 9 | +#include <beman/execution26/detail/set_value.hpp> |
| 10 | +#include <beman/execution26/detail/make_sender.hpp> |
| 11 | +#include <beman/execution26/detail/product_type.hpp> |
| 12 | +#include <beman/execution26/detail/completion_signatures_for.hpp> |
| 13 | +#include <beman/execution26/detail/impls_for.hpp> |
| 14 | +#include <beman/execution26/detail/decayed_typeof.hpp> |
| 15 | +#include <beman/execution26/detail/default_impls.hpp> |
| 16 | +#include <concepts> |
| 17 | +#include <utility> |
| 18 | + |
| 19 | +// ---------------------------------------------------------------------------- |
| 20 | + |
| 21 | +namespace beman::execution26::detail |
| 22 | +{ |
| 23 | + template <typename Completion, typename... T> |
| 24 | + concept just_size |
| 25 | + = (not ::std::same_as<Completion, ::beman::execution26::set_error_t> |
| 26 | + or 1u == sizeof...(T)) |
| 27 | + && (not ::std::same_as<Completion, ::beman::execution26::set_stopped_t> |
| 28 | + or 0u == sizeof...(T)) |
| 29 | + ; |
| 30 | + template <typename Completion> |
| 31 | + struct just_t |
| 32 | + { |
| 33 | + template <typename... T> |
| 34 | + requires ::beman::execution26::detail::just_size<Completion, T...> |
| 35 | + && (::std::movable<::std::decay_t<T>> && ...) |
| 36 | + auto operator()(T&&... arg) const |
| 37 | + { |
| 38 | + return ::beman::execution26::detail::make_sender( |
| 39 | + *this, |
| 40 | + ::beman::execution26::detail::product_type{::std::forward<T>(arg)...} |
| 41 | + ); |
| 42 | + } |
| 43 | + }; |
| 44 | + |
| 45 | + template <typename Completion, typename... T, typename Env> |
| 46 | + struct completion_signatures_for_impl< |
| 47 | + ::beman::execution26::detail::basic_sender< |
| 48 | + just_t<Completion>, |
| 49 | + ::beman::execution26::detail::product_type<T...> |
| 50 | + >, |
| 51 | + Env |
| 52 | + > |
| 53 | + { |
| 54 | + using type = ::beman::execution26::completion_signatures<Completion(T...)>; |
| 55 | + }; |
| 56 | + |
| 57 | + template <typename Completion> |
| 58 | + struct impls_for<just_t<Completion>> |
| 59 | + : ::beman::execution26::detail::default_impls |
| 60 | + { |
| 61 | + static constexpr auto start |
| 62 | + = []<typename State>(State& state, auto& receiver) noexcept -> void |
| 63 | + { |
| 64 | + [&state, &receiver]<::std::size_t... I>(::std::index_sequence<I...>) |
| 65 | + { |
| 66 | + Completion()(::std::move(receiver), |
| 67 | + ::std::move(state.template get<I>())...); |
| 68 | + }(::std::make_index_sequence<State::size()>{}); |
| 69 | + }; |
| 70 | + }; |
| 71 | +} |
| 72 | + |
| 73 | +namespace beman::execution26 |
| 74 | +{ |
| 75 | + using just_t = ::beman::execution26::detail::just_t<::beman::execution26::set_value_t>; |
| 76 | + using just_error_t = ::beman::execution26::detail::just_t<::beman::execution26::set_error_t>; |
| 77 | + using just_stopped_t = ::beman::execution26::detail::just_t<::beman::execution26::set_stopped_t>; |
| 78 | + |
| 79 | + inline constexpr ::beman::execution26::just_t just{}; |
| 80 | + inline constexpr ::beman::execution26::just_error_t just_error{}; |
| 81 | + inline constexpr ::beman::execution26::just_stopped_t just_stopped{}; |
| 82 | +} |
| 83 | + |
| 84 | +// ---------------------------------------------------------------------------- |
| 85 | + |
| 86 | +#endif |
0 commit comments