本文介绍了g ++ 10中的C ++ 20:未定义生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

此MCVE在Visual Studio中可以正常工作。

This MCVE works fine in 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;
}

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

but in g++10, which is listed as having full support or C++20's coroutines, it does not.

(排除实验性没有帮助。)

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

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

It complains that there is no include file generator, and if I take out the #include, that generator is not a part of std:: or is not defined. I suppose there's another name for it in the new standard? Or if not, what do I do instead to get a coroutine that uses co_yield?

推荐答案

中没有任何内容,此外还有协程支持表示支持除了以外的任何东西

Nothing in GCC's status list alongside its coroutine support says it supports anything other than p0912r5, which does not provide std::generator, experimentally or otherwise.

我记得 ;我猜想GCC从来没有做过。

I recall that VS added <experimental/generator> a few years ago; I guess GCC never did.

如果目前建议将其包含在C ++中,并且您可以找到相关的建议,也许可以跟踪其支持状态。但老实说,就目前而言,最好还是编写自己的作品,直到它成为某些实际标准的一部分为止。

If it's currently proposed for inclusion in C++, and you can find the relevant proposal, perhaps you can track its support status. But honestly, for now, you'd be better off writing your own that works until it becomes part of some actual standard.

tl; dr:尽管协程,此功能不属于Coroutines TS的。

tl;dr: Though it is a coroutine, this feature is not part of the Coroutines TS.

这篇关于g ++ 10中的C ++ 20:未定义生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:06