Iterator straw-man

Sean Kelly sean at f4.ca
Tue Nov 7 10:47:12 PST 2006


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);

Yup.  The reason for a proposal is twofold: to establish a common idiom 
for people to follow so code can interact reliably, and to determine 
whether any built-in behavior needs to be tweaked to support iterators 
in a way this is both generic (for UDTs, AAs, and arrays) and elegant.


Sean



More information about the Digitalmars-d mailing list