小编Iro*_*net的帖子

“协程的 Promise 必须声明 'return_value' 或 'return_void'”错误 Visual Studio 2019 C++ 20

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)

c++ c++20 c++-coroutine visual-studio-2019

7
推荐指数
1
解决办法
2003
查看次数

标签 统计

c++ ×1

c++-coroutine ×1

c++20 ×1

visual-studio-2019 ×1