72 points · by dochtman · 12y ago · 32 comments
The (elem : range) proposal seen here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n385...
I'm really looking forward to as well. I wish it could have been in C++14. STL (the guy) is right when he says (auto elem : range) is very tempting. Its so easy for a novice user to not understand they are making a ton of potentially (and likely) unneeded copies. Also in code review its quite common, to see (const auto &elem : range) when it should be (const auto &&elem : range).
After getting bogged down years ago in a crappy C++03 codebase I eased off C++ for a few years, but i must say, the language is really getting better. 5 years ago if you would have told me I would be looking forward to writing something major in C++ I would have laughed.
Note that nothing's wrong with "const auto& elem", except that it prohibits modification. On the other hand, "const auto&& elem" will typically not compile (it'll insist on binding to rvalues, which only proxy iterators return).
Thats of course right about const auto &&.. It won't work, I did mean (auto &&elem : range).
I was at first relieved to see this topic addressed at the top of Q&A, then disappointed to see "Just do it the old way if you want const." I feel that we don't use const enough in C++, and making it easier (yet still clear) to use would be of significant benefit.
If you agree, perhaps there is still time to support "for (const elem : range)" - it seems to me natural and no more disruptive than the rest of the proposal.
For the typical enterprise developer, at least in many of our projects, I am happy that we manly use other languages.
I feel like crying every time I see C style coding in C++, with its usual set of security exploits.
Presumably that should be "decreasing", not "increasing" (or "compilation speed" rather than "compile times").
modules ! modules ! modules !
He's also writing a new book that's available in Rough Cuts from O'Reilly that covers C++11/14: http://scottmeyers.blogspot.com/2014/06/effective-modern-c-s... and has given a talk covering some of the same ground: http://vimeo.com/97318797
Herb Sutter has "Elements of Modern C++ Style": http://herbsutter.com/elements-of-modern-c-style/ and has given several talks, such as http://channel9.msdn.com/Events/Build/2014/2-661
Finally, you can't really beat Stroustrup's book: http://www.amazon.com/The-Programming-Language-4th-Edition/d...
So why forcing everyone to jump through hurdles just to do some simple uses of 2D programming?