Lazy evaluation of function pointers.

Ryan Frame via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 10 15:08:30 PDT 2016


On Sunday, 10 April 2016 at 19:02:06 UTC, Alex Parrill wrote:
>
> A parameter declared as `lazy T` has the type `T delegate()`, 
> which, when called, evaluates the expression that was passed 
> into the function.
>
> So effectively, this:
>
> void foo(lazy int x) { auto i = x(); }
> foo(a+b);
>
> Is the same as this:
>
> void foo(int delegate() x) { auto i = x(); }
> foo(() => a+b);
>
> T in your case is `void function(string)`. So you can do `auto 
> func = f()` to get the function you passed in. It's not very 
> useful in your example to lazily evaluate getting a function 
> pointer, considering it's usually a constant expression after 
> compiling.

That makes sense. Thank you.

--Ryan


More information about the Digitalmars-d-learn mailing list