Cool Trick: Currying for stack-on-heap style delegates
Daniel Keep
daniel.keep.lists at gmail.com
Tue Sep 4 19:40:24 PDT 2007
Russell Lewis wrote:
> As everybody knows, delegate literals currently use a pointer to the
> stack frame as their "this" pointer, meaning that they cannot be
> returned from a function, or used after the frame exits. Some of us
> have argued for a "copy the stack frame" syntax. I'm stumbled upon a
> pretty cool trick to accomplish the same thing (although it can get
> tedious when you draw too many variables into the delegate). The trick
> is to declare a function literal instead of a delegate literal, and then
> use a Curry() template to pass stack variables into the function:
>
> [... snip ...]
There's also this trick:
http://while-nan.blogspot.com/2007/08/fakin-closures.html
-- Daniel
More information about the Digitalmars-d
mailing list