On Friday, 2 October 2015 at 22:57:52 UTC, Walter Bright wrote:
On 10/2/2015 10:49 AM, Eric Niebler wrote:
On Thursday, 1 October 2015 at 21:03:16 UTC, Walter Bright wrote:
I don't see evidence that C++ had ranges before D. Boost ranges are not what
we think of as ranges.

Why not?

Because it returns iterators. It should expose functions (or operators) that do this:

   front
   popFront
   empty

not iterators. Instead, it has:

   begin
   end
   empty

The begin and end are iterators, and don't encapsulate (i.e. constrain) what can be done with those iterators. For example, begin can return an iterator that can be used to increment right on past the end. The iterator itself has no knowledge of where the end is.


For a D range, what happens if you popFront from an empty range? An assertion, I'm guessing. It is not hard for a C++ iterator to do the same, and many debug standard libraries have iterators that do that.


This is the issue that D ranges (and Matthew's and your's) solve. I believe the difference is fundamental.


A C++ iterator can store a pointer back to its range and implement all its core functionality in terms of simple operations like current, next, and done. The Boost.Iterators and Boost.Range libraries made that possible and have been around a long time.

Some iterators can be implemented more efficiently without an indirection to the range. Those iterators are unsafe in the way you describe. The win is that iterators are a more powerful basis for building algorithms (i.e., you can express more with them).


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

It's possible I misunderstand it, please correct me if so.


Reply via email to