<div dir="ltr">On 8 June 2013 09:42, Adam D. Ruppe <span dir="ltr"><<a href="mailto:destructionator@gmail.com" target="_blank">destructionator@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Friday, 7 June 2013 at 23:22:03 UTC, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Currently, to get the instance or function pointers from a delegate, you need to do something like:<br>
</blockquote>
<br></div>
delegates have two members, ptr and funcptr:<br>
<a href="http://dlang.org/function.html" target="_blank">http://dlang.org/function.html</a><br>
<br>
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.<br>
<br>
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.<br>
</blockquote><div><br></div><div style>Indeed, I apologise for my ignorance! The properties are already there... but they're not properly typed.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

idk, I've kinda wanted pointer to members before but I also think D's delegates being so versatile and interchangeable is totally boss.</blockquote><div><br></div><div style>I agree, a delegate is almost always what I want. But a delegate is really just a compound concept, and without a way to express it's fundamental parts, which in certain circumstances (like in my case) are useful on their own, then it feels like a bit of magic.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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,<br>
what is 'C' in the struct template above?<br>
</blockquote>
<br></div>
That's a tricky one, perhaps it could be a tuple of the captured variables' type.<br>
</blockquote></div><br></div><div class="gmail_extra" style>Yeah, that was my initial feeling too... and I think it could be quite workable in that way.</div></div>