| 1 |
// { dg-additional-options "-std=c++20 -fpreprocessed -w" } |
| 2 |
namespace std { |
| 3 |
inline namespace { |
| 4 |
template <typename _Result, typename> struct coroutine_traits { |
| 5 |
using promise_type = _Result::promise_type; |
| 6 |
}; |
| 7 |
template <typename = void> struct coroutine_handle; |
| 8 |
template <> struct coroutine_handle<> { |
| 9 |
public: |
| 10 |
static coroutine_handle from_address(void*); |
| 11 |
void* address(); |
| 12 |
}; |
| 13 |
template <typename> struct coroutine_handle : coroutine_handle<> { |
| 14 |
static coroutine_handle from_address(void*); |
| 15 |
void* address(); |
| 16 |
}; |
| 17 |
struct suspend_always { |
| 18 |
bool await_ready(); |
| 19 |
void await_suspend(coroutine_handle<>); |
| 20 |
void await_resume(); |
| 21 |
}; |
| 22 |
} // namespace |
| 23 |
} // namespace std |
| 24 |
namespace coro = std; |
| 25 |
namespace cppcoro { |
| 26 |
class task { |
| 27 |
private: |
| 28 |
struct awaitable_base { |
| 29 |
coro::coroutine_handle<> m_coroutine; |
| 30 |
bool await_ready() const noexcept; |
| 31 |
void await_suspend(coro::coroutine_handle<> awaitingCoroutine) noexcept; |
| 32 |
}; |
| 33 |
|
| 34 |
public: |
| 35 |
auto operator co_await() const &noexcept { |
| 36 |
struct awaitable : awaitable_base { |
| 37 |
decltype(auto) await_resume() {} |
| 38 |
}; |
| 39 |
return awaitable{m_coroutine}; |
| 40 |
} |
| 41 |
|
| 42 |
private: |
| 43 |
coro::coroutine_handle<> m_coroutine; |
| 44 |
}; |
| 45 |
class shared_task; |
| 46 |
class shared_task_promise_base { |
| 47 |
struct final_awaiter { |
| 48 |
bool await_ready() const noexcept; |
| 49 |
template <typename PROMISE> |
| 50 |
void await_suspend(coro::coroutine_handle<PROMISE> h) noexcept; |
| 51 |
void await_resume() noexcept; |
| 52 |
}; |
| 53 |
|
| 54 |
public: |
| 55 |
coro::suspend_always initial_suspend() noexcept; |
| 56 |
final_awaiter final_suspend() noexcept; |
| 57 |
void unhandled_exception() noexcept; |
| 58 |
}; |
| 59 |
class shared_task_promise : public shared_task_promise_base { |
| 60 |
public: |
| 61 |
shared_task get_return_object() noexcept; |
| 62 |
void return_void() noexcept; |
| 63 |
}; |
| 64 |
class shared_task { |
| 65 |
public: |
| 66 |
using promise_type = shared_task_promise; |
| 67 |
}; |
| 68 |
auto make_shared_task(cppcoro::task awaitable) -> shared_task { |
| 69 |
co_return co_await static_cast<cppcoro::task &&>(awaitable); |
| 70 |
} |
| 71 |
} // namespace cppcoro |