foreach

Sam S E asdf at mailinator.com
Sun Nov 23 07:48:08 PST 2008


Jarrett Billingsley Wrote:

> On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa at sympatioco.ca> wrote:
> > Does foreach use delegates? Isn't that unnecessary overhead?
> > --Sam
> 
> It does use delegates, for iterating over most types.  When iterating
> over arrays, the compiler turns it into a sort of for loop instead.
> 
> Is it unnecessary overhead?  It's not always as fast as it could be,
> but unless someone can figure out some other way of implementing it,
> it's pretty much the best we can get.
> 
> How about iterator objects, like in C++ or Java?  Are they unnecessary
> overhead?  ;)

Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.



More information about the Digitalmars-d mailing list