2727#include " __meta.hpp"
2828#include " __queries.hpp"
2929#include " __type_traits.hpp"
30+ #include " __variant.hpp"
3031
3132#include < exception>
3233#include < functional> // for std::identity
@@ -86,8 +87,7 @@ namespace STDEXEC
8687 using __value_or_void_t = __if_c<__same_as<_Value, void >, __void, _Value>;
8788
8889 template <class _Value >
89- using __expected_t =
90- std::variant<std::monostate, __value_or_void_t <_Value>, std::exception_ptr>;
90+ using __expected_t = __variant<__value_or_void_t <_Value>, std::exception_ptr>;
9191
9292 using __connect_await::__has_as_awaitable_member;
9393
@@ -113,22 +113,22 @@ namespace STDEXEC
113113
114114 constexpr auto await_resume () -> _Value
115115 {
116- // If the operation completed with set_stopped (as denoted by the monostate
117- // alternative being active ), we should not be resuming this coroutine at all.
118- STDEXEC_ASSERT (__result_.index () != 0 );
119- if (__result_.index () == 2 )
116+ // If the operation completed with set_stopped (as denoted by the result variant
117+ // being valueless ), we should not be resuming this coroutine at all.
118+ STDEXEC_ASSERT (! __result_.__is_valueless () );
119+ if (__result_.index () == 1 )
120120 {
121121 // The operation completed with set_error, so we need to rethrow the exception.
122- std::rethrow_exception (std::move (std::get< 2 >(__result_)));
122+ std::rethrow_exception (std::move (__var::__get< 1 >(__result_)));
123123 }
124124 // The operation completed with set_value, so we can just return the value, which
125125 // may be void.
126126 using __reference_t = std::add_rvalue_reference_t <_Value>;
127- return static_cast <__reference_t >(std::get< 1 >(__result_));
127+ return static_cast <__reference_t >(__var::__get< 0 >(__result_));
128128 }
129129
130130 __std::coroutine_handle<> __continuation_;
131- __expected_t <_Value> __result_{};
131+ __expected_t <_Value> __result_{__no_init };
132132 };
133133
134134 // When the sender is not statically known to complete inline, we need to use atomic
@@ -150,24 +150,24 @@ namespace STDEXEC
150150 {
151151 STDEXEC_TRY
152152 {
153- __awaiter_.__result_ .template emplace <1 >(static_cast <_Us&&>(__us)...);
153+ __awaiter_.__result_ .template emplace <0 >(static_cast <_Us&&>(__us)...);
154154 }
155155 STDEXEC_CATCH_ALL
156156 {
157- __awaiter_.__result_ .template emplace <2 >(std::current_exception ());
157+ __awaiter_.__result_ .template emplace <1 >(std::current_exception ());
158158 }
159159 }
160160
161161 template <class _Error >
162162 void set_error (_Error&& __err) noexcept
163163 {
164164 if constexpr (__decays_to<_Error, std::exception_ptr>)
165- __awaiter_.__result_ .template emplace <2 >(static_cast <_Error&&>(__err));
165+ __awaiter_.__result_ .template emplace <1 >(static_cast <_Error&&>(__err));
166166 else if constexpr (__decays_to<_Error, std::error_code>)
167- __awaiter_.__result_ .template emplace <2 >(
167+ __awaiter_.__result_ .template emplace <1 >(
168168 std::make_exception_ptr (std::system_error (__err)));
169169 else
170- __awaiter_.__result_ .template emplace <2 >(
170+ __awaiter_.__result_ .template emplace <1 >(
171171 std::make_exception_ptr (static_cast <_Error&&>(__err)));
172172 }
173173
@@ -236,7 +236,7 @@ namespace STDEXEC
236236 }
237237 STDEXEC_CATCH_ALL
238238 {
239- this ->__awaiter_ .__result_ .template emplace <2 >(std::current_exception ());
239+ this ->__awaiter_ .__result_ .template emplace <1 >(std::current_exception ());
240240 this ->__awaiter_ .__continuation_ .resume ();
241241 }
242242 }
0 commit comments