|
2 | 2 |
|
3 | 3 | namespace std { |
4 | 4 |
|
5 | | -template <typename R, typename...> struct coroutine_traits { |
6 | | - using promise_type = typename R::promise_type; |
| 5 | +template <class Ret, typename... T> struct coroutine_traits { |
| 6 | + using promise_type = typename Ret::promise_type; |
7 | 7 | }; |
8 | 8 |
|
9 | | -template <typename Promise = void> struct coroutine_handle; |
10 | | - |
11 | | -template <> struct coroutine_handle<void> { |
12 | | - static coroutine_handle from_address(void *addr) noexcept { |
13 | | - coroutine_handle me; |
14 | | - me.ptr = addr; |
15 | | - return me; |
16 | | - } |
17 | | - void operator()() { resume(); } |
18 | | - void *address() const noexcept { return ptr; } |
19 | | - void resume() const { } |
20 | | - void destroy() const { } |
21 | | - bool done() const { return true; } |
22 | | - coroutine_handle &operator=(decltype(nullptr)) { |
23 | | - ptr = nullptr; |
24 | | - return *this; |
25 | | - } |
26 | | - coroutine_handle(decltype(nullptr)) : ptr(nullptr) {} |
27 | | - coroutine_handle() : ptr(nullptr) {} |
28 | | - // void reset() { ptr = nullptr; } // add to P0057? |
29 | | - explicit operator bool() const { return ptr; } |
30 | | - |
31 | | -protected: |
32 | | - void *ptr; |
| 9 | +template <class Promise = void> struct coroutine_handle { |
| 10 | + static coroutine_handle from_address(void *) noexcept; |
| 11 | + static coroutine_handle from_promise(Promise &promise); |
| 12 | + constexpr void *address() const noexcept; |
33 | 13 | }; |
34 | 14 |
|
35 | | -template <typename Promise> struct coroutine_handle : coroutine_handle<> { |
36 | | - using coroutine_handle<>::operator=; |
37 | | - |
38 | | - static coroutine_handle from_address(void *addr) noexcept { |
39 | | - coroutine_handle me; |
40 | | - me.ptr = addr; |
41 | | - return me; |
42 | | - } |
43 | | - |
44 | | - Promise &promise() const { |
45 | | - return *reinterpret_cast<Promise *>( |
46 | | - __builtin_coro_promise(ptr, alignof(Promise), false)); |
47 | | - } |
48 | | - static coroutine_handle from_promise(Promise &promise) { |
49 | | - coroutine_handle p; |
50 | | - p.ptr = __builtin_coro_promise(&promise, alignof(Promise), true); |
51 | | - return p; |
52 | | - } |
| 15 | +template <> struct coroutine_handle<void> { |
| 16 | + template <class PromiseType> |
| 17 | + coroutine_handle(coroutine_handle<PromiseType>) noexcept; |
| 18 | + static coroutine_handle from_address(void *); |
| 19 | + constexpr void *address() const noexcept; |
53 | 20 | }; |
54 | 21 |
|
55 | 22 | struct suspend_always { |
56 | 23 | bool await_ready() noexcept { return false; } |
57 | | - void await_suspend(std::coroutine_handle<>) noexcept {} |
| 24 | + void await_suspend(coroutine_handle<>) noexcept {} |
| 25 | + void await_resume() noexcept {} |
| 26 | +}; |
| 27 | + |
| 28 | +struct suspend_never { |
| 29 | + bool await_ready() noexcept { return true; } |
| 30 | + void await_suspend(coroutine_handle<>) noexcept {} |
58 | 31 | void await_resume() noexcept {} |
59 | 32 | }; |
60 | 33 |
|
|
0 commit comments