"the last change" for ranges

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed May 20 19:35:02 PDT 2009


MLT wrote:
> One needs something like a lazy semi-infinite range, that only calls
> a certain function when it reaches an unexplored part.

That's a great abstraction, but we can't afford to impose that to 
everybody. There must be an abstraction for a one-pass go through an 
arbitrarily long stream.

Anyhow, I decided to change ranges as follows:

a) Input:

bool empty();
ref T popNext();

b) Output:

void putNext(T);

c) Forward:

bool empty();
ref T front();
void popFront();

The function ref T popNext() is a nonmember that accepts any forward 
range and uses front() and popFront(). Of course, a forward range is 
welcome to implement popFront as a member if it so wishes. The function 
putNext() overwrites front() and then calls popFront.

d) Bidirectional:

bool empty();
ref T front();
void popFront();
ref T back();
void popBack();

popNext, putNext apply as for forward ranges.

e) Random

bool empty();
ref T front();
void popFront();
ref T back();
void popBack();
ref T opIndex(uint n);
void opIndexAssign(T, uint n);

popNext, putNext apply as for forward ranges. We need to fix the 
opIndexAssign mess.


Andrei



More information about the Digitalmars-d mailing list