On Thursday, 21 September 2017 at 20:32:38 UTC, Jean-Louis Leroy wrote:
It did not take long! Someone tried to create templatized open methods and it didn't work right of the box. I expected that, but in fact there may be a bit of hope. You cannot have virtual function templates in C++ or in D because the layout of the vtables have to be known at compile time - but openmethods creates its method tables at runtime so maybe it can be made to work.

I stumbled upon a problem very quickly: it seems that classes that come from class template instantiations are not registered in ModuleInfo - see below,

[...]

Neither 'Bar!int' nor 'BarInt' appear in 'localClasses'.

Ideas?

Yeah. You can setup a custom registry that maps names to their TypeInfo_Class. I do something similar in iz (though the real point in iz is a GC-free factory but the principle of the registry would be the the same for you)

Example:

---
/+ dub.sdl:
   name "dub_script"
   dependency "iz" version="0.6.0"
+/
module dub_script;

import iz.memory, std.stdio;

class Foo(T){this(){writeln("fooDeInt");}}
TypeInfo_Class[string] registry; // you need that...

static this()
{
registerFactoryClass!(Foo!int)(registry); // ...and that, maybe with another name
}

void main()
{
    auto fooDeInt = iz.memory.factory(registry, "Foo!int");
    destruct(cast(Object) fooDeInt);
}
---

Reply via email to