Is it meaningful to optimize i++ as ++i to avoid the temporary variable?

Viewed 892

Someone told me that I can write

for (iterator it = somecontainer.begin(); it != somecontainer.end(); ++it)

instead of

for (iterator it = somecontainer.begin(); it != somecontainer.end(); it++)

...since the latter one has the cost of an extra unused temporary variable. Is this optimization useful for modern compiler? Do I need to consider this optimization when writing code?

7 Answers
Related