Templates at runtime

Justin mrjnewt at hotmail.com
Thu Feb 12 18:51:01 PST 2009


I'm trying to instantiate a templated class at runtime and having some trouble. My thought is that since something like "Collection!(int)" will return a valid classinfo, I ought to be able to use ClassInfo.find() and then .create:

module test;

import std.stdio;

void main() {

	myClass!(int) c = new myClass!(int)();

	string cName = c.classinfo.name;
	writefln(cName);
	ClassInfo ci = ClassInfo.find(cName);
	assert(ci !is null);                                    // Line 12

	Object o = ci.create();
	assert(o !is null);

}
public class myClass(T) { }

This outputs:
test.myClass!(int).myClass
Error: AssertError Failure test(12)

Is there a way to "find" a classinfo for such a class at runtime?



More information about the Digitalmars-d mailing list