Linked by Hadrien Grasland on Wed 15th Jun 2011 07:32 UTC, submitted by ebasconp
Thread beginning with comment 477276
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[4]: Basically, awesome
by Neolander on Wed 15th Jun 2011 15:33
in reply to "RE[3]: Basically, awesome"
RE[4]: Basically, awesome
by Veto on Thu 16th Jun 2011 09:53
in reply to "RE[3]: Basically, awesome"
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.
RE[5]: Basically, awesome
by dnebdal on Thu 16th Jun 2011 10:01
in reply to "RE[4]: Basically, awesome"
"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?






Member since:
2006-05-09
A lot of features have been added having simplicity as main feature; for example: "auto" and "range-based" for.
For example, to show all items in a vector, in current ISO C++ you need to do something like:
template <typename T>
void show(const vector<T>& v)
{
for (typename vector<T>::const_iterator i =
v.begin(); i != v.end(); i++)
cout << *i << endl;
}
In the new C++0x you can do also this stuff:
template <typename T>
void show(const vector<T>& v)
{
for (auto i = v.begin(); i != v.end(); i++)
cout << *i << endl;
}
or using the range-based loop:
template <typename T>
void show(const vector<T>& v)
{
for (auto& x : v)
cout << i << endl;
}
IMHO, simple, beautiful and powerful because they are new features, but they add simplicity too.