On Fri, 18 Feb 2011 16:15:16 -0500, Sean Eskapp <eatingstap...@gmail.com>
wrote:
Is there a way to "run" a template at compile time, without using a
member?
What I'm trying to do is verify that every element of a tuple is a class
type,
and so far, I've been doing this:
template VerifyTuple(Type, Types...)
{
static assert(is(Type : Object), Type.stringof ~ " is not a class
type.");
static if(Types.length == 0)
alias void dummy;
else
alias VerifyTuple!(Types).dummy dummy;
}
and to use it, I have to do this:
class Foo(T...)
{
alias VerifyTuple!(T).dummy dummy;
}
Is there any way to just "run" the template, without bothering to use the
dummy aliases?
eponymous should help (also cleaned up some of your code):
template VerifyTuple(Types...)
{
static if(Types.length == 0)
enum bool VerifyTuple = true;
else
enum bool VerifyTuple == is(Type : Object) &&
VerifyTuple!(Types[1..$]);
}
class Foo(T...)
{
static assert(VerifyTuple!(T...), "one of types in " ~ T.stringof ~ "
is not a class");
}
It doesn't identify the specific type that isn't a class, but that could
be done with a separate template.
-Steve