10template<
typename,
typename...>
11struct coroutine_traits {};
13template<
typename R,
typename... Args>
14requires(
requires {
typename R::promise_type; })
15struct coroutine_traits<R, Args...> {
16 using promise_type =
typename R::promise_type;
19template<
typename Promise =
void>
20struct coroutine_handle;
23struct coroutine_handle<void> {
25 constexpr coroutine_handle() noexcept = default;
26 constexpr coroutine_handle(std::nullptr_t) noexcept {}
28 constexpr auto operator=(std::nullptr_t)
noexcept -> coroutine_handle& {
29 m_frame_pointer =
nullptr;
33 auto done() const noexcept ->
bool {
return __builtin_coro_done(m_frame_pointer); }
34 constexpr explicit operator bool() const noexcept {
return bool(m_frame_pointer); }
36 void operator()()
const { resume(); }
37 void resume()
const { __builtin_coro_resume(m_frame_pointer); }
39 void destroy()
const { __builtin_coro_destroy(m_frame_pointer); }
41 constexpr auto address() const noexcept ->
void* {
return m_frame_pointer; }
42 constexpr static auto from_address(
void* address)
noexcept -> coroutine_handle {
43 coroutine_handle result;
44 result.m_frame_pointer = address;
49 void* m_frame_pointer {
nullptr };
52template<
typename Promise>
53requires(!di::concepts::LanguageVoid<Promise>)
54struct coroutine_handle<Promise> {
56 constexpr coroutine_handle() noexcept = default;
57 constexpr coroutine_handle(std::nullptr_t) noexcept {}
59 constexpr auto operator=(std::nullptr_t)
noexcept -> coroutine_handle& {
60 m_frame_pointer =
nullptr;
64 constexpr operator coroutine_handle<>() const noexcept {
return std::coroutine_handle<>::from_address(address()); }
66 auto done() const noexcept ->
bool {
return __builtin_coro_done(m_frame_pointer); }
67 constexpr explicit operator bool() const noexcept {
return bool(m_frame_pointer); }
69 void operator()()
const { resume(); }
70 void resume()
const { __builtin_coro_resume(m_frame_pointer); }
72 void destroy()
const { __builtin_coro_destroy(m_frame_pointer); }
74 auto promise() const -> Promise& {
75 void* promise_pointer = __builtin_coro_promise(m_frame_pointer,
alignof(Promise),
false);
76 return *
static_cast<Promise*
>(promise_pointer);
78 static auto from_promise(Promise& promise) -> coroutine_handle {
79 coroutine_handle result;
80 result.m_frame_pointer = __builtin_coro_promise((
char*) &promise,
alignof(Promise),
true);
84 constexpr auto address() const noexcept ->
void* {
return m_frame_pointer; }
85 constexpr static auto from_address(
void* address)
noexcept -> coroutine_handle {
86 coroutine_handle result;
87 result.m_frame_pointer = address;
92 void* m_frame_pointer {
nullptr };
95constexpr auto operator==(std::coroutine_handle<> a, std::coroutine_handle<> b)
noexcept ->
bool {
96 return a.address() == b.address();
99constexpr auto operator<=>(std::coroutine_handle<> a, std::coroutine_handle<> b)
noexcept -> std::strong_ordering {
100 return a.address() <=> b.address();
103struct noop_coroutine_promise {};
106struct coroutine_handle<noop_coroutine_promise> {
109 constexpr static void noop() {}
111 void (*resume)() = noop;
112 void (*destroy)() = noop;
113 struct noop_coroutine_promise promise;
115 static Frame static_frame;
118 constexpr operator coroutine_handle<>() const noexcept {
return std::coroutine_handle<>::from_address(address()); }
120 constexpr auto done() const noexcept ->
bool {
return false; }
121 constexpr explicit operator bool() const noexcept {
return true; }
123 constexpr void operator()() const noexcept { resume(); }
124 constexpr void resume() const noexcept {}
126 constexpr void destroy() const noexcept {}
128 constexpr auto promise() const noexcept -> noop_coroutine_promise& {
return static_frame.promise; }
130 constexpr auto address() const noexcept ->
void* {
return m_frame_pointer; }
133 friend auto noop_coroutine() noexcept -> coroutine_handle;
135 explicit coroutine_handle() noexcept = default;
137 void* m_frame_pointer { &static_frame };
140using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
142inline noop_coroutine_handle::Frame noop_coroutine_handle::static_frame {};
144inline auto noop_coroutine() noexcept -> noop_coroutine_handle {
145 return noop_coroutine_handle();
148struct suspend_never {
149 constexpr auto await_ready() const noexcept ->
bool {
return true; }
150 constexpr void await_suspend(std::coroutine_handle<>)
const noexcept {}
151 constexpr void await_resume() const noexcept {}
154struct suspend_always {
155 constexpr auto await_ready() const noexcept ->
bool {
return false; }
156 constexpr void await_suspend(std::coroutine_handle<>)
const noexcept {}
157 constexpr void await_resume() const noexcept {}
163template<
typename Promise =
void>
172using std::noop_coroutine;
frame::FrameImpl< di::ByteBuffer > Frame
Definition frame.h:73
constexpr auto operator==(Duration< Rep1, Period1 > const &a, Duration< Rep2, Period2 > const &b) -> bool
Definition duration.h:108
constexpr auto operator<=>(Duration< Rep1, Period1 > const &a, Duration< Rep2, Period2 > const &b)
Definition duration.h:115
constexpr auto destroy
Definition destroy.h:35
OperationState< Receiver >::promise_type Promise
Definition connect_awaitable.h:118
Definition zstring_parser.h:9
std::suspend_never SuspendNever
Definition coroutine.h:170
std::coroutine_handle< Promise > CoroutineHandle
Definition coroutine.h:164
std::noop_coroutine_handle NoopCoroutineHandle
Definition coroutine.h:166
std::noop_coroutine_promise NoopCoroutinePromise
Definition coroutine.h:167
std::suspend_always SuspendAlways
Definition coroutine.h:169
Definition enable_generate_structed_bindings.h:46