protocol for using InputRanges

Regan Heath regan at netmail.co.nz
Wed Mar 26 08:09:04 PDT 2014


On Wed, 26 Mar 2014 12:30:53 -0000, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:

> On Wed, 26 Mar 2014 08:29:15 -0400, Steven Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>
>> On Wed, 26 Mar 2014 06:46:26 -0400, Regan Heath <regan at netmail.co.nz>  
>> wrote:
>>> IMO the rules should be something like:
>>>   - r.empty WILL return false if there is more data available in the  
>>> range.
>>>
>>>   - r.empty MUST be called before r.front, r.front WILL succeed if  
>>> r.empty returned false.
>>>   - r.front WILL repeatably return the current element in the range.  
>>> It MAY return by value or by reference.
>>>
>>>   - r.empty SHOULD be called before r.popFront, otherwise r.popFront  
>>> MAY do nothing or throw
>>>     (could also make this one a 'MUST')
>>>   - r.popFront WILL advance to the next element in the range.
>>
>> These two rules are not necessary if you know the range is not empty.  
>> See the conversation inside this pull:  
>> https://github.com/D-Programming-Language/phobos/pull/1987
>
> Gah, I didn't cut out the right rules. I meant the two rules that empty  
> must be called before others. Those are not necessary.

I see.  I was thinking we ought to make empty mandatory to give more  
guaranteed structure for range implementors, so lazy initialisation can be  
done in one place only, etc etc.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list