Lazy evaluation
OF
nospam at nospammington.com
Thu Jun 28 05:46:43 PDT 2007
BCS Wrote:
> OF wrote:
> > It hints at lazyexp not being valid after the function has ended, which makes it quite different from delegates.
>
> This is the /exact/ behavior of delegate liters and delegates formed
> from nested functions. They are invalid after the function call they are
> from returns. This is because the delegate caries a pointer to the stack
> frame of the surrounding function.
Yes, you're right. It's probably the delegate created in
this(lazy T exp)
{
mExp = { return exp(); };
}
that's the problem.
this(T delegate() exp)
{
mExp = { return exp(); };
}
crashes too. That's what I get for not doing my homework...
I suppose my only hope would be some kind of casting from lazy T to T delegate(), but seems I'm out of luck.
More information about the Digitalmars-d
mailing list