The magic behind foreach (was: Re: Descent 0.5.3 released)
Christopher Wright
dhasenan at gmail.com
Fri Jan 23 15:24:51 PST 2009
Bill Baxter wrote:
> It's not?
>
> foreach(i; things) {
> if (i==a) continue;
> if (i==b) break;
> if (i==d) return;
> if (i==c) goto somewhere;
> }
>
> Those are all fairly common things to do from inside the 'dg' call.
> The int is how the compiler distinguishes which case got you out of
> the dg.
>
> --bb
You didn't read my post carefully.
The use case you would lose is:
int opApply (int delegate(something) dg)
{
auto result = dg(stuff);
if (result)
{
// This would be impossible if we took a void delegate.
log ("iteration stopped early");
return result;
}
return 0;
}
More information about the Digitalmars-d
mailing list