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

Ary Borenszweig ary at esperanto.org.ar
Sat Jan 24 09:06:12 PST 2009


Christopher Wright wrote:
> 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;
> }

Why would you ever want to do that??



More information about the Digitalmars-d mailing list