RFC on range design for D2

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Sep 9 18:16:07 PDT 2008


Lionello Lunesu wrote:
> 
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
> news:ga5r8i$h0v$1 at digitalmars.com...
>> So in essence the behavior is that you can use isEmpty to
>> make sure that getNext won't blow in your face (speaking of Pulp
>> Fiction...)
> 
> So isEmpty is optional for input ranges? This does not actually match 
> your own documentation:
> 
>> getNext: The call is defined only right after r.isEmpty returned false.
> 
> If you make isEmpty optional, its non-constness is less of a problem. 
> What I have a problem with (overstatement) is having to call isEmpty to 
> actually prepare the next element. If try { while (1) e = ir.getNext; } 
> works, I'm sold : )

I think I'd want to make it nonoptional such that people wanting real 
fast iterators can define r.isEmpty to do a check and r.getNext (well, 
r.left) to go unchecked.

>> r.isEmpty does whatever the hell it takes to make sure whether there's
>> data available or not. It is not const and it could throw an exception.
>>
>> v = r.getNext returns BY VALUE by means of DESTRUCTIVE COPY data that
>> came through the wire, data that the client now owns as soon as getNext
>> returned. There is no extra copy, no extra allocation, and the real
>> thing has happened: data has been read from the outside and user code
>> was made the only owner of it.
> 
> Thank you for taking the time to explain all these details. This is all 
> great stuff.

However, superdan destroyed me. (See my answer to him.) I think I need 
to concede to your design.

Andrei


More information about the Digitalmars-d-announce mailing list