Performance difference between ++iterator and iterator++?

后端 未结 7 1089
悲哀的现实
悲哀的现实 2020-12-08 04:32

My workmate claims that for object types preincrement is more efficient than post increment

e.g.

std::vector vec;

... insert a wh         


        
7条回答
  •  没有蜡笔的小新
    2020-12-08 05:24

    I have read that it makes no difference with compilers that have a decent optimizer. Since the overall loop logic is the same for both, it makes sense to use a pre increment as a good programming habit. That way, if the programmer encounters the "suboptimal" compiler, the best outcome is assured.

提交回复
热议问题