digitalmars.D - detect if a symbol is template
- Lirong (10/10) Feb 17 2010 Hi,
- Igor Lesik (20/28) Feb 18 2010 imo, it is not possible; template name is not a type
- Lars T. Kyllingstad (12/28) Feb 18 2010 Is there any use case where it is useful to just know whether something
- Lirong (4/37) Feb 18 2010 Thank you!
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
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
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
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 regardsIs 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









Igor Lesik <curoles yahoo.com> 