public void Consumer()
{
foreach(int i in Integers())
{
Console.WriteLine(i.ToString());
}
}
public IEnumerable<int> Integers()
{
yield return 1;
yield return 2;
yield return 4;
yield return 8;
yield return 16;
yield return 16777216;
}
有没有办法通过模板技巧(或其他)在 c++ 中获得相同的语法?
原文由 Guillaume Paris 发布,翻译遵循 CC BY-SA 4.0 许可协议
看看 boost::Coroutine。它做你想做的事。 http://www.crystalclearsoftware.com/soc/coroutine/index.html#coroutine.intro
教程中的示例
http://www.crystalclearsoftware.com/soc/coroutine/coroutine/tutorial.html