|
| 1 | +// include/beman/execution/detail/sync_wait_with_variant.hpp -*-C++-*- |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#ifndef INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT |
| 5 | +#define INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT |
| 6 | + |
| 7 | +#include <beman/execution/detail/common.hpp> |
| 8 | +#include <beman/execution/detail/suppress_push.hpp> |
| 9 | +#ifdef BEMAN_HAS_IMPORT_STD |
| 10 | +import std; |
| 11 | +#else |
| 12 | +#include <optional> |
| 13 | +#include <utility> |
| 14 | +#endif |
| 15 | +#ifdef BEMAN_HAS_MODULES |
| 16 | +import beman.execution.detail.apply_sender; |
| 17 | +import beman.execution.detail.callable; |
| 18 | +import beman.execution.detail.call_result_t; |
| 19 | +import beman.execution.detail.get_domain_early; |
| 20 | +import beman.execution.detail.into_variant; |
| 21 | +import beman.execution.detail.sender_in; |
| 22 | +import beman.execution.detail.sync_wait; |
| 23 | +import beman.execution.detail.value_types_of_t; |
| 24 | +#else |
| 25 | +#include <beman/execution/detail/apply_sender.hpp> |
| 26 | +#include <beman/execution/detail/callable.hpp> |
| 27 | +#include <beman/execution/detail/call_result_t.hpp> |
| 28 | +#include <beman/execution/detail/get_domain_early.hpp> |
| 29 | +#include <beman/execution/detail/into_variant.hpp> |
| 30 | +#include <beman/execution/detail/sender_in.hpp> |
| 31 | +#include <beman/execution/detail/sync_wait.hpp> |
| 32 | +#include <beman/execution/detail/value_types_of_t.hpp> |
| 33 | +#endif |
| 34 | + |
| 35 | +// ---------------------------------------------------------------------------- |
| 36 | + |
| 37 | +namespace beman::execution::detail { |
| 38 | +template <::beman::execution::sender_in<::beman::execution::detail::sync_wait_env> Sndr> |
| 39 | +using sync_wait_with_variant_result_type = |
| 40 | + ::std::optional<::beman::execution::value_types_of_t<Sndr, ::beman::execution::detail::sync_wait_env>>; |
| 41 | +} // namespace beman::execution::detail |
| 42 | + |
| 43 | +namespace beman::execution { |
| 44 | + |
| 45 | +struct sync_wait_with_variant_t { |
| 46 | + template <typename Sndr> |
| 47 | + requires ::beman::execution::detail::callable< |
| 48 | + ::beman::execution::sync_wait_t, |
| 49 | + ::beman::execution::detail::call_result_t<::beman::execution::into_variant_t, Sndr>> |
| 50 | + auto apply_sender(Sndr&& sndr) const { |
| 51 | + using result_type = ::beman::execution::detail::sync_wait_with_variant_result_type<Sndr>; |
| 52 | + if (auto opt_value = |
| 53 | + ::beman::execution::sync_wait(::beman::execution::into_variant(::std::forward<Sndr>(sndr)))) { |
| 54 | + return result_type(::std::move(::std::get<0>(*opt_value))); |
| 55 | + } |
| 56 | + return result_type(::std::nullopt); |
| 57 | + } |
| 58 | + |
| 59 | + template <typename Sndr> |
| 60 | + requires requires { typename ::beman::execution::detail::sync_wait_with_variant_result_type<Sndr>; } |
| 61 | + auto operator()(Sndr&& sndr) const { |
| 62 | + return ::beman::execution::apply_sender( |
| 63 | + ::beman::execution::detail::get_domain_early(sndr), *this, ::std::forward<Sndr>(sndr)); |
| 64 | + } |
| 65 | +}; |
| 66 | + |
| 67 | +inline constexpr sync_wait_with_variant_t sync_wait_with_variant{}; |
| 68 | +} // namespace beman::execution |
| 69 | + |
| 70 | +// ---------------------------------------------------------------------------- |
| 71 | + |
| 72 | +#include <beman/execution/detail/suppress_pop.hpp> |
| 73 | + |
| 74 | +#endif // INCLUDED_BEMAN_EXECUTION_DETAIL_SYNC_WAIT_WITH_VARIANT |
0 commit comments