On 10/2/15 6:57 PM, 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.

The solution to this is cursors. i.e. ranges that point at exactly one element.

All dcollection ranges have begin and end accessors for cursors to the first and one beyond the last element, but unlike iterators you cannot do anything dangerous with them.

What you CAN do, is construct ranges from them safely (there is a slight cost for this). The interface is much superior IMO to how containers do ranges in std.container.

There is a deficiency in ranges in that they are very fragile when it comes to pointing at one element. Iterators are much better in this regard.

-Steve

Reply via email to