Finding class template instantiations via runtime reflection (for openmethods)

Jean-Louis Leroy jl at
Thu Sep 21 20:32:38 UTC 2017

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 

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

import std.stdio;

class Foo {}

class Bar(T) : Foo
   int i;

alias BarInt = Bar!int;

const barInt = new BarInt;

void main()
   foreach (mod; ModuleInfo) {
     foreach (c; mod.localClasses) {


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


More information about the Digitalmars-d mailing list