On Monday, 8 June 2015 at 01:15:30 UTC, Mike Parker wrote:
I know how to use a range :) What I'm asking about is a requirement on implementing front on a custom range. Is there a rule that says when I implement my own range, consecutive calls to front must return the same value until popFront is called?

Example:
Is this a valid implementation of front?
auto front() { return _member++; }

Or must it be this:
auto front() { return _member; }
void popFront() { ++_member; }

My current understanding is that the former is incorrect, but I'm looking for confirmation of that. I can't find it written down anywhere.

Here is how it is implemented in the book of Andrew:

@property bool empty(T)(T[] a) { return a.length == 0; }
@property ref T front(T)(T[] a) { return a[0]; }
void popFront(T)(ref T[] a) { a = a[1 .. $]; }

Reply via email to