On Friday, 7 June 2013 at 23:22:03 UTC, Manu wrote:
Currently, to get the instance or function pointers from a delegate, you need to do something like:

delegates have two members, ptr and funcptr:
http://dlang.org/function.html

As a fun fact, if you modify druntime's allocator to be malloc(), you can use free(delegate.ptr) to manually manage closures, though this takes a lot of care to know if it actually should be freed or not.

Anyway, the ptr member there is always void*, however, so at least one cast is required to actually use it. Perhaps the language could be extended to make this strongly typed, but then you'd have to change the whole visible type as assigning say, a closure to a delegate variable would need to be a different type than a class member; I guess this is what you're talking about though.

idk, I've kinda wanted pointer to members before but I also think D's delegates being so versatile and interchangeable is totally boss.

I don't know a syntax to describe the type of a closure, so when a delegate is typed with a closure instead of a struct/class,
what is 'C' in the struct template above?

That's a tricky one, perhaps it could be a tuple of the captured variables' type.

Reply via email to