From 89b90bcfbe115d8971620b7fc5a9dc0fd24143e1 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Feb 2026 13:00:07 -0800 Subject: [PATCH 1/2] replace `std::variant` with `__variant` in `as_awaitable` --- include/stdexec/__detail/__as_awaitable.hpp | 35 ++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/include/stdexec/__detail/__as_awaitable.hpp b/include/stdexec/__detail/__as_awaitable.hpp index 2270d39c4..07c3f8476 100644 --- a/include/stdexec/__detail/__as_awaitable.hpp +++ b/include/stdexec/__detail/__as_awaitable.hpp @@ -25,11 +25,11 @@ #include "__queries.hpp" #include "__tag_invoke.hpp" #include "__type_traits.hpp" +#include "__variant.hpp" #include #include // for std::identity #include -#include namespace STDEXEC { @@ -81,8 +81,7 @@ namespace STDEXEC using __value_or_void_t = __if_c<__same_as<_Value, void>, __void, _Value>; template - using __expected_t = - std::variant, std::exception_ptr>; + using __expected_t = __variant<__value_or_void_t<_Value>, std::exception_ptr>; template concept __completes_inline_for = __never_sends<_Tag, _Sender, _Env...> @@ -103,11 +102,11 @@ namespace STDEXEC { STDEXEC_TRY { - __result_.template emplace<1>(static_cast<_Us&&>(__us)...); + __result_.template emplace<0>(static_cast<_Us&&>(__us)...); } STDEXEC_CATCH_ALL { - __result_.template emplace<2>(std::current_exception()); + __result_.template emplace<1>(std::current_exception()); } } @@ -115,11 +114,11 @@ namespace STDEXEC void set_error(_Error&& __err) noexcept { if constexpr (__decays_to<_Error, std::exception_ptr>) - __result_.template emplace<2>(static_cast<_Error&&>(__err)); + __result_.template emplace<1>(static_cast<_Error&&>(__err)); else if constexpr (__decays_to<_Error, std::error_code>) - __result_.template emplace<2>(std::make_exception_ptr(std::system_error(__err))); + __result_.template emplace<1>(std::make_exception_ptr(std::system_error(__err))); else - __result_.template emplace<2>(std::make_exception_ptr(static_cast<_Error&&>(__err))); + __result_.template emplace<1>(std::make_exception_ptr(static_cast<_Error&&>(__err))); } __expected_t<_Value>& __result_; @@ -136,8 +135,8 @@ namespace STDEXEC void set_stopped() noexcept { - // no-op: the __result_ variant will remain engaged with the monostate - // alternative, which signals that the operation was stopped. + // no-op: the __result_ variant will remain valueless, which signals that the + // operation was stopped. } // Forward get_env query to the coroutine promise @@ -185,7 +184,7 @@ namespace STDEXEC } STDEXEC_CATCH_ALL { - this->__result_.template emplace<2>(std::current_exception()); + this->__result_.template emplace<1>(std::current_exception()); this->__continuation_.resume(); } } @@ -207,21 +206,21 @@ namespace STDEXEC constexpr auto await_resume() -> _Value { - // If the operation completed with set_stopped (as denoted by the monostate - // alternative being active), we should not be resuming this coroutine at all. - STDEXEC_ASSERT(__result_.index() != 0); - if (__result_.index() == 2) + // If the operation completed with set_stopped (as denoted by the result variant + // being valueless), we should not be resuming this coroutine at all. + STDEXEC_ASSERT(!__result_.__is_valueless()); + if (__result_.index() == 1) { // The operation completed with set_error, so we need to rethrow the exception. - std::rethrow_exception(std::move(std::get<2>(__result_))); + std::rethrow_exception(std::move(__var::__get<1>(__result_))); } // The operation completed with set_value, so we can just return the value, which // may be void. - return static_cast>(std::get<1>(__result_)); + return static_cast>(__var::__get<0>(__result_)); } protected: - __expected_t<_Value> __result_{}; + __expected_t<_Value> __result_{__no_init}; }; ////////////////////////////////////////////////////////////////////////////////////// From d6d7b24414ea805fc5880778441aad6960efb912 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Fri, 27 Feb 2026 13:46:07 -0800 Subject: [PATCH 2/2] missed an edit --- include/stdexec/__detail/__as_awaitable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stdexec/__detail/__as_awaitable.hpp b/include/stdexec/__detail/__as_awaitable.hpp index 07c3f8476..0bdbd124e 100644 --- a/include/stdexec/__detail/__as_awaitable.hpp +++ b/include/stdexec/__detail/__as_awaitable.hpp @@ -268,7 +268,7 @@ namespace STDEXEC STDEXEC::start(__opstate); } - if (this->__result_.index() == 0) + if (this->__result_.__is_valueless()) { // The operation completed with set_stopped, so we need to call // unhandled_stopped() on the promise to propagate the stop signal. That will