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

Bill Baxter wbaxter at gmail.com
Thu Jan 22 21:30:29 PST 2009


On Fri, Jan 23, 2009 at 11:59 AM, Jarrett Billingsley
<jarrett.billingsley at gmail.com> wrote:
> On Thu, Jan 22, 2009 at 9:38 PM, Bill Baxter <wbaxter at gmail.com> wrote:
>>
>> Yep, that was the gist of it.  Put the return value on the stack of
>> the calling frame.
>> Nothing all that fancy really, just you want to be able to hide that
>> __result = blah ugliness from the user.
>
> Oh, I'm suggesting that the compiler do this instead of us having to
> do it with macros.

I see what you're saying now.  So the user has to manipulate a bool
return value instead of an int?

Then you could have

void opApply(bool delegate(ref int) dg) {
      foreach(i; internal_) {
            if (dg(i)) return;
      }
}

Yep, that looks like an improvement to me.



More information about the Digitalmars-d mailing list