How to call destroy() in @nogc?
cc
cc at nevernet.com
Tue May 24 02:29:38 UTC 2022
```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);
return mem !is null ? emplace!T(mem[0..size], args) : null;
}
void FREE(T)(ref T obj) @nogc if (is(T == class)) {
auto mem = cast(void*) obj;
scope(exit) free(mem);
destroy(obj);
obj = null;
}
class Foo {
~this() @nogc {}
}
void main() {
auto foo = NEW!Foo;
FREE(foo);
}
```
```
Error: `@nogc` function `nogctest.FREE!(Foo).FREE` cannot call
non- at nogc function `object.destroy!(true, Foo).destroy`
```
Is this not currently possible? Found this thread:
https://forum.dlang.org/thread/zanuuhzmqxljadcexmgv@forum.dlang.org?page=1
is it still unresolved?
More information about the Digitalmars-d-learn
mailing list