October 01, 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.
October 01, 2015
On Thursday, 1 October 2015 at 05:47:25 UTC, Eric Niebler wrote:
> 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
>

That's good news !

> 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.

Well, yes and no. Sure I'm sure there are precedent for ranges, be it in C++ or even I'm sure one can find them in other languages. I'm sure someone in the 70s had something like ranges already.

But for years, it was a fringe idea in the C++ world, the consensus being the iterator were enough. Meanwhile, D adopted the idea and ran with it, doing so, proving how powerful the concept is.

Some may be bitter, but I'm actually happy that C++ is adopting ranges, as these are a great tool. As long as the Jobs "we reinvented hot water with shiny corners and it is a revolution" style of presenting things do not become the norm. On that note, I think Herb's pissed of a lot of people with his talk. On the other hand, I think you did a fine job.

October 01, 2015
On 9/30/2015 10:47 PM, Eric Niebler wrote:
> 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.

Range iteration over arrays have been around in D since the beginning
and a more general proposal first appears here:

http://www.digitalmars.com/d/archives//12773.html

and Matthew Wilson did his range library for D in 9/2004 (and one for C++, too). He said he was going to propose it for Boost, I don't know if he ever did. It does appear in his "Imperfect C++" book. Matthew, a bit to my frustration, would always implement the D ideas first for C++ :-) but I don't think they garnered any attention from the C++ community.

news://news.digitalmars.com/rangelib

Here's something I wrote to Matthew in Feb 2004:

"I think ranges in D are the same thing as slices. C++ doesn't have slices,
so ranges makes sense as a distinct object. In D, slices over a collection
or array simply yield a subset collection or subset array, not a separate
object, so I'm not sure what value they would add to D."

I found a link to Thorsten's Boost range:

http://www.boost.org/doc/libs/1_34_0/libs/range/doc/intro.html
http://www.boost.org/doc/libs/1_34_0/libs/range/doc/range.html

It returns an iterator, so I don't think it is what we'd consider a range to be today.

Matthew's ranges had the following members:

    current
    advance
    is_open

corresponding to front, popFront, and empty.

So I'd say given what I can dig up, that D's ranges were more advanced than Boost's were at the time.

Sadly, Matthew's work seems to have disappeared from the internets and his web sites have vanished (rangelib.org).

Update: found it on web.archive.org!

https://web.archive.org/web/20050427085507/http://rangelib.synesis.com.au/

Anyhow, this is what I could dig up in an hour or so.
October 01, 2015
Ranges because a D core language feature with D 2.021 Nov 25, 2008.

Core language feature meaning it was no longer just a library construction, it was supported by foreach loops.

As a library feature, it appeared in D 2.008 Nov 27, 2007.
October 01, 2015
On Thursday, 1 October 2015 at 08:37:37 UTC, Walter Bright wrote:
> Sadly, Matthew's work seems to have disappeared from the internets and his web sites have vanished (rangelib.org).
>
> Update: found it on web.archive.org!
>
> https://web.archive.org/web/20050427085507/http://rangelib.synesis.com.au/
>
> Anyhow, this is what I could dig up in an hour or so.

That site is still up, at least for me:

http://rangelib.synesis.com.au/
October 01, 2015
On 10/1/2015 2:31 AM, Joakim wrote:
> On Thursday, 1 October 2015 at 08:37:37 UTC, Walter Bright wrote:
>> Sadly, Matthew's work seems to have disappeared from the internets and his web
>> sites have vanished (rangelib.org).
>>
>> Update: found it on web.archive.org!
>>
>> https://web.archive.org/web/20050427085507/http://rangelib.synesis.com.au/
>>
>> Anyhow, this is what I could dig up in an hour or so.
>
> That site is still up, at least for me:
>
> http://rangelib.synesis.com.au/

I have the Oct 2004 issue of CUJ where Matthew Wilson writes about ranges:

"Ranges are simple to use and implement and, for most of the components written so far, are compilable by a majority of commonly used compilers. They're so simple that you may wonder why no one has defined them before."

Boost ranges are still not modern ranges:

http://www.boost.org/doc/libs/1_59_0/libs/range/doc/html/range/concepts/single_pass_range.html

Eric's ranges are modern ranges for C++. Matthew had them for C++ 10 years ago, but his work was forgotten. He was going to propose it for Boost, but I don't know what happened.
October 01, 2015
On Thursday, 1 October 2015 at 05:47:25 UTC, Eric Niebler wrote:

...[snip]...
>
> Hope that clears things up.

It does, thank you.

>
> 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.

Fair point, I did overlook boost.range when considering the C++ range options.

bye
lobo



October 01, 2015
On Thursday, 1 October 2015 at 05:47:25 UTC, Eric Niebler wrote:
> 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.

Did you look at my example(this one is updated)?
http://ideone.com/X1JAEn

I've factored out a 'range_iterator' in this version. I would probably rethink the way I've done the chaining, but there is nothing complicated about adding foreach support as I've implemented it in my example. From the callers point of view, it's a typedef and two functions.

I really doubt anything could be done that would offer a perceptible performance gain over what I've done in my example.

I suppose it's a moot point if C++ is actually planning native range support.

    Bit

October 01, 2015
On Thursday, 1 October 2015 at 09:25:37 UTC, Walter Bright wrote:
> Ranges because a D core language feature with D 2.021 Nov 25, 2008.
>
> Core language feature meaning it was no longer just a library construction, it was supported by foreach loops.
>
> As a library feature, it appeared in D 2.008 Nov 27, 2007.

Please be excited to see ranges in C++20
October 01, 2015
On 10/01/2015 01:37 AM, Walter Bright wrote:

> Update: found it on web.archive.org!
>
> https://web.archive.org/web/20050427085507/http://rangelib.synesis.com.au/
>
> Anyhow, this is what I could dig up in an hour or so.

Thank you for mining for that.

From the days that I used to frequent comp.lang.c++.moderated (before around 2009 or so), I remember an individual who was trying to sell the idea of ranges to the C++ community. As I remember, nobody took him seriously at that time. Reading the page above, I think that individual must have been John Torjo or Matthew Wilson.

Ali