26.11.2012 20:36, Manu пишет:
template isThing( alias symbol, A )
{
   enum isThing = false;
}

This template works in most contexts:

int x;
struct S {}

pragma(msg, isThing!x);
pragma(msg, isThing!S);

But this fails:
pragma(msg, isThing!int);

Why does it fail on a basic type (int), but not a user defined type (S)?
How can I fix the template declaration to not error in that case?
I tried:

template isThing( alias symbol, A )
{
   enum isThing = false;
}
template isThing( T, A )
{
   enum isThing = false;
}

Hoping the T version would catch the int, but this leads to different
errors "matches more than one template declaration".

First, your `isThing` requires 2 parameters so all examples will fail to compile. Probably you meant `isThing(alias symbol)`.

Second, build-in type isn't a valid template alias parameter (probably as it isn't a "symbol"), see docs:
http://dlang.org/template.html#TemplateAliasParameter

Third, a workaround is to use template tuple parameter (as already suggested in this thread).

--
Денис В. Шеломовский
Denis V. Shelomovskij

Reply via email to