#include #include struct coro { struct promise_type { coro get_return_object() { return handle_type::from_promise(*this); } std::suspend_always initial_suspend() noexcept { return {}; } std::suspend_always final_suspend() noexcept { return {}; } void unhandled_exception() {} }; using handle_type = std::coroutine_handle; handle_type handle; coro(handle_type h) : handle(h) {} ~coro() { if (handle) handle.destroy(); } }; coro f() { std::printf("cogito"); co_await std::suspend_always{}; std::printf("ergo"); co_await std::suspend_always{}; std::printf("sum!\n"); } int main() { coro c = f(); while (!c.handle.done()) { std::printf(" -> "); c.handle.resume(); } }