#include #include #include struct fiber { struct promise_type { fiber get_return_object() { return {handle_type::from_promise(*this)}; } std::suspend_always initial_suspend() { return {}; } std::suspend_always final_suspend() noexcept { return {}; } void return_void() {} void unhandled_exception() {} }; using handle_type = std::coroutine_handle; handle_type handle = nullptr; fiber(std::coroutine_handle h): handle(h) {} ~fiber() { if (handle) handle.destroy(); } }; fiber make_fiber() { for (auto i: {0, 1, 2, 3, 4}) { printf("%i ", i); co_await std::suspend_always(); } } int main() { auto f = make_fiber(); while (!f.handle.done()) f.handle.resume(); puts(""); }