The magic behind foreach (was: Re: Descent 0.5.3 released)

Christopher Wright dhasenan at gmail.com
Thu Jan 22 15:10:57 PST 2009


Ary Borenszweig wrote:
> If the compiler can transform a "foreach" into an opApply call, passing 
> the foreach body and converting breaks to "return 1" statements... can't 
> opApply be specified as:
> 
> int opApply(void delegate(ref uint) dg) { // note: delegate returns void
> }
> 
> and the compiler transforms the opApply signature to the one that's used 
> now, plus converting each dg call to a call and a check of return value 
>  != 0 and return 1 in that case?

This only fails if you wish to take a particular action when the calling 
code breaks out of iteration. This is not such a large use case that I 
think it worth preserving.



More information about the Digitalmars-d mailing list