> Failing that, C++14 may introduce Ranges.
It would have been nice to have some sort of simple range syntax added to C or C++ long ago. In the true spirit of C, don't even make it safe, just make it bloody well work.
FirstArray[0..3] = SecondArray[4..7];
case 2..10:
for(int i : 0..ArrayLength)
for(int i : ArrayLength..0)
(hah that'd prove horrible if ArrayLength ended up being a negative number, obviously some proper syntax would need to be determined :) )
I am always annoyed that such simple things are ignored in the language. Sure they don't enable any "cool new abilities", but they make using the language a lot more friendly (especially in comparison to having a ton of case fall through statements!)
The problem is your proposed [] syntax implies random access. Many algorithms and data structures don't require or support random access.
Re:Edward C++Hands
by general_failure on Friday September 20, 2013 @12:49AM
(#6415986)
reverse iterate a string? i have never done that
Actually, in C++, you ideally wouldn't reverse the string at all... you'd just call str.rbegin() and str.rend() to grab the reverse iterators, and pass them straight to your next algorithm.
The two approaches are just as consistent as one another, Python just uses a terser syntax (which, in my opinion, isn't as obvious).
In C++14, if all things go according to plan with Concepts Lite, you'll be able to write a short 3-5 line, reusable, version of reverse() that takes your string (or container) as one argument, deduces at compile time, during overload resolution, that begin() and end() return bidirectional iterators, and then does the right thing. Failing that, C++14 may introduce Ranges. So C++ is only getting terser.