"the last change" for ranges

Kristian Kilpi kjkilpi at gmail.com
Wed May 20 13:37:34 PDT 2009


On Wed, 20 May 2009 21:02:02 +0300, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Robert Jacques wrote:
>> Bicycle shed: Well, since output ranges use 'put', how about 'get' for  
>> input ranges?
>
> Nice color :o). In fact, "put" is a poor choice because it doesn't  
> reflect advancement. Probably putNext and getNext are better.
>
> Andrei

(Just thinking aloud... :) ) I have been using get() + set() and read() +  
write().
read() and write() advance to the next item; get() + set() do not.

Actually I have implemented my iterator classes (in C++) as follows  
(simplified):

BasicIFlow:
read()
toNext()
isEnd()

IFlow:
get()
read()
toNext()
isEnd()

Iter:
get()
read()
toNext()
toPrev()
isBegin()
isFirst()
isLast()
isEnd()

As seen, Iter is a two-way iterator, and the other two are one-way  
iterators. (And there are correponding output iterators too, of course.)

There are also functions like toFirst(), toEnd(), etc (only Iter has  
toFirst()). And for convenience, Iter also has functions like getNext()  
and getPrev() that return the next/previous item without moving the  
iterator. So there are quite many functions, which is not necessary good  
;) (although many of them have default functionality that simply calls the  
other "core" functions; for example, read() *could* be written with get()  
+ toNext()).

I know very little about Ranges (when I have time, that will change), but  
if I'm not mistaken, they hold and modify the beginning and end of the  
iterated area? That's an interesting and unique approach. :) My classes  
move a cursor inside the iterated area. Of course, with the Flow classes,  
the beginning of the area is moved together with the cursor (as the cursor  
cannot move backwards).



More information about the Digitalmars-d mailing list