C ++重复N次迭代 [英] c++ repeat N iterations
本文介绍了C ++重复N次迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以清楚地执行以下操作:
I can clearly do something like this:
for(int i = 0; i < 10000; i++)
testIteration();
但是是否有任何std函数在一行中做类似的事情?像这样的东西:
But is there any std functions which does similar thing in one line? Something like that:
std::repeat(10000, testIteration);
推荐答案
在 C ++ 20的拟议标准中有一个 iota_view
的示例:
for (int i : iota_view{1, 10})
cout << i << ' '; // prints: 1 2 3 4 5 6 7 8 9
但现在, range-v3 库:
for (int _ : view::iota{0, 10})
testIteration(); // calls testIteration 10 times.
这篇关于C ++重复N次迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文