detect if a symbol is template

Lirong leon.li.lirong at gmail.com
Thu Feb 18 02:07:42 PST 2010


Thank you!

This solves my problem.

I want to know a symbol is template so that I can use mixin with it.



Lars T. Kyllingstad Wrote:

> Lirong wrote:
> > Hi,
> > 
> > Can anyone show me how to detect if a symbol is template?
> > 
> > The following is not working:
> > 
> > template A()
> > {
> > ...
> > }
> > 
> > alias a A;
> > 
> > static if(is (a == template)) // error
> > 
> > Best regards
> 
> Is there any use case where it is useful to just know whether something 
> is a template or not?
> 
> A template really can't be used for anything without instantiating it, 
> and to instantiate it you need to know what parameters it takes. 
> Checking whether a symbol is a template that takes a certain set of 
> parameters is easy:
> 
>    template Foo() { ... }
>    template Bar(T) { ... }
> 
>    static if (__traits(compiles, Foo!())) { ... }
>    static if (__traits(compiles, Bar!int)) { ... }
> 
> -Lars




More information about the Digitalmars-d mailing list