在c ++ 11中,如果我在向量上使用基于范围的循环,是否可以保证迭代顺序?说,是否可以保证以下代码块具有相同的输出?
vector<T> output;
vector<U> V;
for( auto v: V) output.push_back(f(v));
与
for(int i =0; i < V.size(); ++i) output.push_back(f(V[i]));
如果不是vector
,该map
怎么办?
是的,保证这两个代码可以做到相同。尽管我没有标准的链接,但您可以在这里看看。我引用:You can read that as "for all x in v" going through starting with v.begin() and iterating to v.end().
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句