front stability

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 30 16:50:47 PDT 2016


On 6/2/2016 5:51 AM, Steven Schveighoffer wrote:
> I have always treated ranges with this expectation:
>
> 1. front gets you the current element of the range. Calling front multiple times
> without calling popFront should get you the same value.
> 2. popFront moves you to the next element of the range if it exists.

Right. Also:

3. empty can be called multiple times in a row, and must always return the same 
result.
4. it is not legal to call front() on an empty range, but it is not required to 
call empty() first
5. it is not legal to call popFront() on an empty range, but it is not required 
to call empty() or front() first.

> I'd say violating the expectations of what popFront and front do is more
> egregious than a particular use case, no matter how valid that case is. I'd like
> to fix this bug, but I see there were quite a few major D contributors in the
> camp that wanted this function to behave the way it is. So I'd rather first
> debate the merits here.

This was debated at length in the past. The result was the rules above. Ranges 
that do not follow those rules need to be fixed. I don't think there's a need to 
debate it again.



More information about the Digitalmars-d mailing list