Linked by Hadrien Grasland on Wed 15th Jun 2011 07:32 UTC, submitted by ebasconp
General Development "The recently finished C++ ISO standard, with the working name of C++0x, is due to be published this summer, following the finishing touches to the ISO spec language and standards wonks agreed upon in March."
Thread beginning with comment 477382
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[4]: Basically, awesome
by Veto on Thu 16th Jun 2011 09:53 UTC in reply to "RE[3]: Basically, awesome"
Veto
Member since:
2010-11-13

for (auto i = v.begin(); i != v.end(); i++)


In the educative example above, you should really use ++i instead of i++. This may seem like nitpicking, but there is a significant performance difference. When using i++, the compiler will have to invoke the copy constructor at each iteration.

Reply Parent Score: 2

RE[5]: Basically, awesome
by dnebdal on Thu 16th Jun 2011 10:01 in reply to "RE[4]: Basically, awesome"
dnebdal Member since:
2008-08-27

"for (auto i = v.begin(); i != v.end(); i++)


In the educative example above, you should really use ++i instead of i++. This may seem like nitpicking, but there is a significant performance difference. When using i++, the compiler will have to invoke the copy constructor at each iteration.
"

I thought most modern compilers were smart enough to recognize that you're not using the unincremented value, and thus do the right thing?

Reply Parent Score: 1

RE[6]: Basically, awesome
by ba1l on Thu 16th Jun 2011 11:23 in reply to "RE[5]: Basically, awesome"
ba1l Member since:
2007-09-08

Assuming that the compiler can inline the overloaded ++ operator (which it should in this case), and you have a trivial copy constructor (which again, should be the case), modern compilers should be able to completely remove the copy. Probably.

Reply Parent Score: 2

RE[6]: Basically, awesome
by Carewolf on Sun 19th Jun 2011 18:20 in reply to "RE[5]: Basically, awesome"
Carewolf Member since:
2005-09-08

If the interface is external (from a frame-work or shared library) the compiler can often not do those kinds of optimizations. With C++ overloading there is no guarantee that ++i and i++ has the same effect when used as procedure calls.

Reply Parent Score: 2