www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - detect if a symbol is template

reply Lirong <leon.li.lirong gmail.com> writes:
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
Feb 17 2010
next sibling parent Igor Lesik <curoles yahoo.com> writes:
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
imo, it is not possible; template name is not a type in this particular case, to check if a is alias for A, you may use: A.stringof == a.stringof -Igor ----- Original Message ---- From: Lirong <leon.li.lirong gmail.com> To: digitalmars-d puremagic.com Sent: Wed, February 17, 2010 10:18:43 PM Subject: detect if a symbol is template 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
Feb 18 2010
prev sibling parent reply "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
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
Feb 18 2010
parent Lirong <leon.li.lirong gmail.com> writes:
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
Feb 18 2010