Templates at runtime

Simen Kjaeraas simen.kjaras at gmail.com
Sun Feb 15 03:52:16 PST 2009


On Fri, 13 Feb 2009 03:51:01 +0100, Justin <mrjnewt at hotmail.com> wrote:

> 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?

This is already bugzilla'd. http://d.puremagic.com/issues/show_bug.cgi?id=2484

--
Simen



More information about the Digitalmars-d mailing list