Iterator straw-man

Sean Kelly sean at f4.ca
Wed Nov 8 08:46:48 PST 2006


Bill Baxter wrote:
> Craig Black wrote:
>> I do agree that using classes and interfaces to represent iterators is 
>> a bad idea for performance reasons.  I also agree that I don't think 
>> it's necessary to support raw pointers.
>>
>> IMO iterators should be structs such that iteration can be performed 
>> as follows:
>>
>> for(auto i = container.begin(); i.isValid(); i.next())  write(i.value);
>>
>> If I am not mistaken, this can already be done in D.  With foreach 
>> support this would simplify to.
>>
>> foreach(i; container)  write(i);
> 
> I haven't read Seans big long proposal yet, but I think the method that 
> returns an iterator should not be called 'begin'.  I should be called 
> 'forward' or 'iterator' or 'iter' or 'forward_iterator' or something 
> like that.

I agree.  In my proposal I used fwdIt and revIt for lack of a better idea.


Sean



More information about the Digitalmars-d mailing list