Код: Выделить всё
struct Foo
{
/* ... */
};
struct GenericPromise
{
std::suspend_always initial_suspend() noexcept { return {}; }
std::suspend_always final_suspend() noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
virtual ~GenericPromise() = default;
};
struct Coroutine
{
std::coroutine_handle handle;
struct promise_type : Foo, GenericPromise
{
Coroutine get_return_object()
{
return { std::coroutine_handle::from_promise(*this) };
}
int AdditionalData = 42;
};
};
Coroutine Coro()
{
co_return;
}
int main(int argc, char* argv[])
{
Coroutine coro = Coro();
coro.handle.resume();
assert(coro.handle.done());
coro.handle.destroy();
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... c-promises