What should happen here?
Steven Schveighoffer
schveiguy at gmail.com
Wed Sep 22 21:06:11 UTC 2021
On 9/21/21 8:02 AM, Steven Schveighoffer wrote:
> I just thought of a possible easy and effective way to ensure the thing
> isn't collected early:
>
> ```d
> struct Pin(T)
> {
> T t;
> @nogc nothrow pure @safe ~this() {}
> alias t this;
> }
>
> ...
> // usage
> auto c = Pin!C(new C); // now it needs to be held until the scope ends
> ```
I made a package for something like this:
https://code.dlang.org/packages/keepalive
Maybe it might find some use.
-Steve
More information about the Digitalmars-d
mailing list