Get template and its instantiation parameters

Michal Minich michal at minich.sk
Wed Oct 7 07:23:08 PDT 2009


If one has a template instance, is it possible to get template name and parameter 
type that was used for instantiating, at compile time?

consider:

class List (T) {}

List!(int) lst;
Foo (lst);

I want to create such template Foo which prints:
List!(int)
List
int

Something simiar for Arrays can be created:
int[char] x;
Foo (x);

template Foo (X : T[U], T, U)
{
    void Foo (X arr)
    {
        writeln(typeof(arr).stringof);
        writeln(T.stringof);
        writeln(U.stringof);
    }
}

but similar template for template instances does not work:
template Foo (X : T!(U), T, U) // does not matches List!(int)

when is changed to something more specific, it starts working:
template Foo (X : List!(U), U) // matches List!(int)




More information about the Digitalmars-d-learn mailing list