1919
2020#include " __as_awaitable.hpp"
2121#include " __concepts.hpp"
22+ #include " ../coroutine.hpp" // IWYU pragma: keep for __coro::coroutine_handle
2223
2324#include < exception>
2425
2526namespace stdexec {
2627#if !STDEXEC_STD_NO_COROUTINES()
2728 namespace __was {
2829 template <class _Promise = void >
29- class __continuation_handle ;
30+ class __coroutine_handle ;
3031
3132 template <>
32- class __continuation_handle <void > {
33+ class __coroutine_handle <void > : __coro::coroutine_handle< > {
3334 public:
34- __continuation_handle () = default ;
35+ __coroutine_handle () = default ;
3536
3637 template <class _Promise >
37- __continuation_handle (__coro::coroutine_handle<_Promise> __coro) noexcept
38- : __coro_ (__coro) {
38+ __coroutine_handle (__coro::coroutine_handle<_Promise> __coro) noexcept
39+ : __coro::coroutine_handle<> (__coro) {
3940 if constexpr (requires (_Promise& __promise) { __promise.unhandled_stopped (); }) {
4041 __stopped_callback_ = [](void * __address) noexcept -> __coro::coroutine_handle<> {
4142 // This causes the rest of the coroutine (the part after the co_await
@@ -53,43 +54,46 @@ namespace stdexec {
5354
5455 [[nodiscard]]
5556 auto handle () const noexcept -> __coro::coroutine_handle<> {
56- return __coro_ ;
57+ return * this ;
5758 }
5859
5960 [[nodiscard]]
6061 auto unhandled_stopped () const noexcept -> __coro::coroutine_handle<> {
61- return __stopped_callback_ (__coro_. address ());
62+ return __stopped_callback_ (address ());
6263 }
6364
6465 private:
6566 using __stopped_callback_t = __coro::coroutine_handle<> (*)(void *) noexcept ;
6667
67- __coro::coroutine_handle<> __coro_{};
6868 __stopped_callback_t __stopped_callback_ = [](void *) noexcept -> __coro::coroutine_handle<> {
6969 std::terminate ();
7070 };
7171 };
7272
7373 template <class _Promise >
74- class __continuation_handle {
74+ class __coroutine_handle : public __coroutine_handle <> {
7575 public:
76- __continuation_handle () = default ;
76+ __coroutine_handle () = default ;
7777
78- __continuation_handle (__coro::coroutine_handle<_Promise> __coro) noexcept
79- : __continuation_ {__coro} {
78+ __coroutine_handle (__coro::coroutine_handle<_Promise> __coro) noexcept
79+ : __coroutine_handle<> {__coro} {
8080 }
8181
82- auto handle () const noexcept -> __coro::coroutine_handle<_Promise> {
83- return __coro::coroutine_handle<_Promise>::from_address (__continuation_. handle (). address ( ));
82+ static auto from_promise (_Promise& __promise) noexcept -> __coroutine_handle {
83+ return __coroutine_handle ( __coro::coroutine_handle<_Promise>::from_promise (__promise ));
8484 }
8585
86- [[nodiscard]]
87- auto unhandled_stopped () const noexcept -> __coro::coroutine_handle<> {
88- return __continuation_.unhandled_stopped ();
86+ auto promise () const noexcept -> _Promise& {
87+ return __coro::coroutine_handle<_Promise>::from_address (address ()).promise ();
8988 }
9089
91- private:
92- __continuation_handle<> __continuation_{};
90+ auto handle () const noexcept -> __coro::coroutine_handle<_Promise> {
91+ return __coro::coroutine_handle<_Promise>::from_address (address ());
92+ }
93+
94+ operator __coro::coroutine_handle<_Promise>() const noexcept {
95+ return handle ();
96+ }
9397 };
9498
9599 struct __with_awaitable_senders_base {
@@ -99,12 +103,12 @@ namespace stdexec {
99103 __continuation_ = __hcoro;
100104 }
101105
102- void set_continuation (__continuation_handle <> __continuation) noexcept {
106+ void set_continuation (__coroutine_handle <> __continuation) noexcept {
103107 __continuation_ = __continuation;
104108 }
105109
106110 [[nodiscard]]
107- auto continuation () const noexcept -> __continuation_handle <> {
111+ auto continuation () const noexcept -> __coroutine_handle <> {
108112 return __continuation_;
109113 }
110114
@@ -113,7 +117,7 @@ namespace stdexec {
113117 }
114118
115119 private:
116- __continuation_handle <> __continuation_{};
120+ __coroutine_handle <> __continuation_{};
117121 };
118122
119123 template <class _Promise >
@@ -127,6 +131,6 @@ namespace stdexec {
127131 } // namespace __was
128132
129133 using __was::with_awaitable_senders;
130- using __was::__continuation_handle ;
134+ using __was::__coroutine_handle ;
131135#endif
132136} // namespace stdexec
0 commit comments