How long does the context of a delegate exist?
Paul Backus
snarwin at gmail.com
Sun May 30 10:43:22 UTC 2021
On Sunday, 30 May 2021 at 09:39:28 UTC, cc wrote:
>
> Is there any way to enforce at compile time that we're not
> accidentally allocating when creating a delegate, other than
> being carefully aware of what variables are referenced inside
> the body? Something like:
> ```d
> auto dg = delegate {...}
> assert(dg.ptr is null, "Oops, we unintentionally allocated on
> GC here, check delegate body!"); // can't static assert
> ```
`@nogc`. Or check the output of `dmd -vgc` if you want something
less strict.
More information about the Digitalmars-d-learn
mailing list