VS2019最新的c++编译器。
\n错误是:“协程的承诺必须声明‘return_value’或‘return_void’”
\n从 David Mazi\xc3\xa8res https://www.scs.stanford.edu/~dm/blog/c++-coroutines.html 博客中提取的示例\n在不同的编译器 GCC 10.2 下工作。
\n我无法获取在 VS2019 中编译的源代码。
\n#include <concepts>\n#include <coroutine>\n#include <exception>\n#include <iostream>\nstruct ReturnObject {\n struct promise_type {\n ReturnObject get_return_object() { return {}; }\n std::suspend_never initial_suspend() { return {}; }\n std::suspend_never final_suspend() noexcept { return{}; }\n void unhandled_exception() {}\n \n };\n};\n\nstruct Awaiter {\n std::coroutine_handle<>* hp_;\n constexpr bool await_ready() const noexcept { return false; }\n void await_suspend(std::coroutine_handle<> h) { *hp_ = h; }\n constexpr void await_resume() const noexcept {}\n};\n\nReturnObject\ncounter(std::coroutine_handle<>* continuation_out)\n{\n Awaiter a{ …Run Code Online (Sandbox Code Playgroud)