Convert a delegate to a function (i.e. make a thunk)
Jonathan M Davis
jmdavisProg at gmx.com
Wed Apr 25 14:27:21 PDT 2012
On Wednesday, April 25, 2012 14:02:53 Mehrdad wrote:
> It would be nice if there was a way to convert delegates to
> functions/thunks, because certain annoying tasks (e.g. 'WndProc's in
> Windows) would become a heck of a lot easier.
>
> Is there any way to already do this? If not, how about adding a toFunction()
> method in std.functional?
>
> (This would of course require making data executable, so that's why it's
> painful to get right. ATL uses a pool of some sort, I think... so if
> toFunction() did this internally, with a separate pool, it would reduce a
> lot of memory management burden from the programmer.)
You could have a function which took a delegate and called it (which could
probably be done with void* if the function has to be an extern(C) function),
or if the function didn't need to be pure, then you could have a function
which called a module-level variable which the delegate had been assigned to.
But you can't convert a delegate to a function without passing the delegate to
the function one way or another, because the function doesn't have a context
(not being a delegate).
- Jonathan M Davis
More information about the Digitalmars-d
mailing list