According to the language manual you can wrap 'new' together with the type name so that nim automatically use new.
https://nim-lang.org/docs/manual.html#importcpp-pragma-importcpp-for-procs
proc newFoo(a, b: cint): ptr Foo {.importcpp: "new Foo(@)".}
which is kinda nice, however its counterpart of delete is not documented.
Can you wrap delete in a similar way so that the deconstructor is also run?
Also similarly is it possible to use the nim GC allocator instead, so that the C++ constructor/deconstructor are run when being constructed/deconstructed during allocation and when the object goes out of scope?
Yes, you can wrap a delete like this:
proc delete[T](val : ptr T ) : void {.importcpp:"delete #".}
Yes, you can wrap a delete like this:
proc delete[T](val : ptr T ) : void {.importcpp:"delete #".}
Thank you for your reply. This is useful and not obvious for newcomers. Documentation should be updated to clarify this common use case.