Shout out to D at cppcon, when talkign about ranges.

Eric Niebler via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 30 22:47:23 PDT 2015


On Thursday, 1 October 2015 at 04:08:00 UTC, bitwise wrote:
> I understand, but the C++ committee seems very conservative to 
> me, so when it's this easy to add for(:) support by giving 
> ranges begin()/end() functions, it makes me doubt they will 
> actually change the language for it.

As of C++11, C++ has the for(auto e:range) control structure you 
are looking for. I would be using it here except for one thing: 
in my proposal, begin() and end() don't have to return objects of 
the same type! begin() must return an iterator and end() must 
return something that is EqualityComparable with the iterator -- 
but it doesn't have to be an iterator. That makes many types of 
iterators vastly simpler to implement and more efficient at 
runtime.

C++'s built-in range-based for(:) loop expects begin() and end() 
to return objects of the same type. The committee is already 
talking about loosening that constraint so that the ranges I'm 
proposing Just Work with the existing built-in looping construct. 
Until then, there is an ugly macro. It's a temporary hack, 
nothing more.

Hope that clears things up.

Eric

P.S. I see lots of people here assuming that C++ is playing 
catch-up to D because D has ranges and C++ doesn't yet. That is 
ignoring the long history of ranges in C++. C++ got ranges in the 
form of the Boost.Range library by Thorsten Ottoson sometime in 
the early 00's. Andrei didn't implement D's ranges until many 
years after. The ranges idea is older than dirt. It's not a D 
invention.


More information about the Digitalmars-d mailing list