foreach

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 12 20:04:08 PDT 2014


"Manu via Digitalmars-d"  wrote in message 
news:mailman.2111.1402626404.2907.digitalmars-d at puremagic.com...

> It gets awkward when you nest, using '_' leads to '__',

i,j,k,etc work just fine.  Are you really nesting your loops that deeply?

> and
> personally, I would expect an 'unreferenced variable' warning for the
> unused loop counter. I like warnings hassling me about unused
> variables.

This is a good point.

> I also object to the inconsistency with for(;;). Recall Scott Myers 
> talk...

Should we also allow "foreach(;)" ?  'for' being so loose is not necessarily 
something we want to copy.

> It's theoretically an optimisation too; capturing front may be a
> costly operation that's not required. Ranges maintain their counters
> internally, there's no reason to emit code to capture a local copy of
> 'front' if it's not used. popFront and empty don't imply a byVal copy,
> they usually just update range counters.

The compiler's optimizer will do that just fine. 



More information about the Digitalmars-d mailing list