On Tuesday, 21 March 2017 at 08:46:43 UTC, Ali Çehreli wrote:
Another option is std.conv.emplace:import std.conv : emplace; class MyClass { this(int) @nogc { } ~this() @nogc { } } void method(bool flag) @nogc { void[__traits(classInstanceSize, MyClass)] buffer = void; MyClass obj; if(flag) { obj = emplace!MyClass(buffer, 1); } else { obj = emplace!MyClass(buffer, 2); } // Unfortunately, destroy() is not @nogc // scope(exit) destroy(obj);
Thank you for clarification. But I have one more question. Do I have to use destroy for deallocating object from stack?
