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