Re: How to call destroy() in @nogc?

2022-05-24 Thread Adam Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 14:11:57 UTC, Steven Schveighoffer wrote: Note it has no idea what the real object type is at this point, just that it is an Object (which does not have a @nogc destructor). It actually has nothing to do with Object. It doesn't have a destructor at all, so there's

Re: How to call destroy() in @nogc?

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/23/22 10:29 PM, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size);

Re: How to call destroy() in @nogc?

2022-05-24 Thread cc via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:55:06 UTC, Tejas wrote: On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo` Interesting, thanks.

Re: How to call destroy() in @nogc?

2022-05-23 Thread Tejas via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo`

How to call destroy() in @nogc?

2022-05-23 Thread cc via Digitalmars-d-learn
```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size); scope(failure) free(mem);