will range based for loop in c++ preserve the index order

后端 未结 3 1459
别那么骄傲
别那么骄傲 2020-12-30 23:58

in c++11, if I use a range based for loop on vector, will it guarantee the iterating order? say, will the following code blocks are guaranteed for same output?



        
3条回答
  •  渐次进展
    2020-12-31 00:55

    Yes the two codes are guaranteed to do the same. Though I don't have a link to the standard you can have a look here. I quote: You can read that as "for all x in v" going through starting with v.begin() and iterating to v.end().

提交回复
热议问题