6 ms·
Great Write Up. There is a ton of information packed in there. C++17 looks like it will be a major improvement like C++11 was. Very much looking forward to Modu
by r-s 12y ago
Great Write Up. There is a ton of information packed in there. C++17 looks like it will be a major improvement like C++11 was. Very much looking forward to Modules.
The (elem : range) proposal seen here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm 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.
- cageface 12y agoI've had the same experience. Hadn't really touched C++ since the late 90's and had traumatic memories from those times but working in my own C++11 codebase recently has been both pleasant and surprisingly productive. The language is headed in the right direction but it's a big ship to steer.
- pjmlp 12y agoI love the language, but mostly on personal projects. 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.
- shmerl 12y agoI'm pretty glad we use C++ in enterprise development (and extra glad we use C++11) ;) There are barely any other languages which can replace it yet. Rust is a good candidate.
- pjmlp 12y agoWell I imagine you are lucky to work in an enterprise world where you get to pick skilled developers and are allowed to make proper use of C++. I have seen quite a few projects with developers that could barely handle VB, being thrown to C++ projects. Others where the style guide was making it, C compiled with a C++ compiler.
- shmerl 12y ago> I have seen quite a few projects with developers that could barely handle VB, being thrown to C++ projects. I'm not sure why would anyone do that, if they want to produce a quality result. Finding good programmers and engineers is hard though. > Others where the style guide was making it, C compiled with a C++ compiler. Yes, that can be pretty annoying, and I had to deal with maintaining such code in the past. Luckily this doesn't happen anymore in our development.
- pjmlp 12y ago> I'm not sure why would anyone do that, if they want to produce a quality result. Pay as less as possible for project costs.
- cageface 12y agoYou're lucky to be able to use such a recent standard in enterprise dev. Those shops tend to be pretty conservative in my experience. Where do you work?
- deleted 12y ago[deleted]
- shmerl 12y agoIt happened fairly recently, after the switch to the newest gcc, because we basically decoupled the compiler from the underlying distro (using cross compilation), so compiler could be updated independently. For a long time we were stuck with an old gcc.
- StephanTLavavej 12y agoIt took me some time to recognize the problem with range-for (after testing its implementation in VC 2012), and more time to work up the courage to write a Core Language proposal. I also wish next-gen range-for had gotten into C++14, but that's mostly a formality - compilers can (and often do) ship features as soon as they're voted into the Working Paper. 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).
- r-s 12y agoFirst off, its Great to see you on HN! For the few of you who don't know, Stephan maintains Visual Studio's C++ Standard Library implementation and he is extremely well regarded in C++ circles. Thats of course right about const auto &&.. It won't work, I did mean (auto &&elem : range).
- jzwinck 12y agoAs I was reading through your "for (elem : range)" proposal I became quite anxious to know how adding const would be handled. I was hoping that "for (const elem : range)" would be added to mean "for (const auto& elem : range)" because I very often find myself within a non-const method having a non-const container but wanting to iterate with no chance of modifying it. 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.
- StephanTLavavej 12y agoI talked about this some more in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3994.htm http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n399... Q17. Many people have asked for such syntax, but I am wary of adding more complexity to the Core Language. Ultimately, I believe that this should be handled on the range side instead of the element side. What Evolution/Core needs to do is to fix the problem with nested temporaries in range-for loops - the problem (affecting both C++11's range-for and mine) is that range-for will keep temporary ranges alive if they're the topmost thing returned, but not if you have "const T& noop(const T&)" and you try to loop over noop(return_temporary_range()). They're aware of the problem, which is a start. If and when that's fixed, then what you want can be handled through library tech: "for (elem : as_const(range))".
- deleted 12y ago[deleted]