相关疑难解决方法(0)

g++10 中的 C++20:未定义生成器

此 MCVE 在 Visual Studio 中运行良好。

#include <experimental/generator>
#include <iostream>

std::experimental::generator<int> f() { for (int i = 0; i < 10; ++i) co_yield i; }

int main ()
{
    for (int i : f())
        std::cout << i << ' ';

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是在被列为完全支持或 C++20 的协程的 g++10 中,它没有。

(取出experimental并没有帮助。)

我正在编译:g++ -g -std=c++2a -fcoroutines -c main.cpp

它抱怨没有包含文件生成器,如果我取出#include,该生成器不是 std:: 的一部分或未定义。我想在新标准中它还有另一个名字吗?或者,如果没有,我该怎么做才能获得使用 的协程co_yield

c++ coroutine c++20 c++-coroutine

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

标签 统计

c++ ×1

c++-coroutine ×1

c++20 ×1

coroutine ×1