Let's get the semantic around closure fixed.
Adam D. Ruppe
destructionator at gmail.com
Thu May 20 12:10:31 UTC 2021
On Thursday, 20 May 2021 at 11:40:24 UTC, Ola Fosheim Grostad
wrote:
> But delegates have to work without a GC too
Well they do... sort of.
You can always take the address of a struct member function and
now you have your nogc delegate.
Of course the difficulty is the receiving function has no way to
knowing if that void* it received is a struct or an automatically
captured variable set or what.
And the capture list takes a little work but there's tricks like
making it all in a struct.
I wrote about this not too long ago:
http://dpldocs.info/this-week-in-d/Blog.Posted_2021_03_01.html#tip-of-the-week
However the delegate itself is less useful than a functor or
interface though unless you must pass it to existing code. And
then unless it is a `scope` receiver you're asking for a leak
anyway again because of that void* being unknown to the caller
(which is why this is possible at all, but also it leaves you a
bit stuck).
It would be kinda cool if the compiler would magically pack small
types into that void* sometimes. Since it is opaque to the caller
it could actually pack in a captured int or two right there and
be a by-value delegate.
More information about the Digitalmars-d
mailing list