Iterators Must Go

Fawzi Mohamed fmohamed at mac.com
Sat May 9 15:25:37 PDT 2009


On 2009-05-09 18:06:48 +0200, Sean Kelly <sean at invisibleduck.org> said:

> Walter Bright wrote:
>> 
>> If you had an iterator that knew its beginning and end, then the whole 
>> paradigm of:
>> 
>>    for (iterator i = begin; i != end; i++)
>> 
>> doesn't make much sense because of the redundancy.
> 
> Yup.  And most of the "interesting" iterators fall into this 
> category--the one returned from begin or rbegin is the real iterator 
> and the one returned from end or rend is just used to tell the real 
> cursor to check whether it's at the end or not.  This is why I 
> commented on Andrei's statement that it's impossible to make an 
> iterator for a delimited range.  It's possible, the design is just 
> unnatural.

Indeed I have always argued that the unbundling of the iterator end 
done by C++ was a bad idea.
All other languages that have iterators or generators did not make this 
mistake, and luckily it seems that D2 did not either.
I had to argue but finally ranges have ForwardRange and the possibility 
to check the head with another Range
I would call that (which is in my opinion the most general and useful) 
simply Iterator because that is what it is, and iterator which knows 
its end (as generators in python, iterators in Aldor, and almost all 
languages that want to be reasonably safe).
Anyway as long as it works and for_each works on them I don't care much 
about the name used...

Fawzi




More information about the Digitalmars-d mailing list