"the last change" for ranges

dsimcha dsimcha at yahoo.com
Wed May 20 19:52:14 PDT 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> 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

(Bangs head against desk.)  Sorry.  Didn't see the part about the non-member
popNext(), though this would require Walter to make extension methods work for
structs, which should probably happen anyway.



More information about the Digitalmars-d mailing list