For very long reasons I'd like to be able to generate C++ constructor with initialization list.
The ultimate goal is being able to inherit from a C++ class like so:
++
struct Net : torch::nn::Module {
Net(int64_t N, int64_t M)
: linear(register_module("linear", torch::nn::Linear(N, M)))
{ }
torch::nn::Linear linear;
};
AFAIK for C++ inheritance we just need the pure and inheritable pragma so that Nim doesn't add its own runtime typeinfo:
type
Module* {.pure, inheritable, importcpp: "torch::nn::Module".} = object
but the initialization list constructor eludes me. Here is an example with less domain-specific noise:
+++
class MyClass {
public:
MyClass() : m_classID(-1), m_userdata(0) {
}
int m_classID;
void *m_userdata;
};
Yes, but this is supposed to be written by end users who want to define their own neural nets.
That said, I'll create a template/macro to properly emit that.