On Monday, 22 August 2016 at 00:43:00 UTC, Engine Machine wrote:
The following code works and does what I want!
template InstantiateOrEmptySeq(alias tmpl, args...)
{
alias Seq(T...)=T;
static if (args.length > 0)
alias InstantiateOrEmptySeq = tmpl!(args[0 .. $-1]);
else
alias InstantiateOrEmptySeq = Seq!();
}
class T(A...) : InstantiateOrEmptySeq!(T, A)
{
static if (A.length == 0)
{
// Base class
int x;
} else
static if (A[$-1] == "Animal")
{
int y;
} else
static if (A[$-1] == "Dog")
{
int z;
} else
static if (A[$-1] == "Pug")
{
int s;
} else static assert(A[$-1]~" not a defined class of
"~this.stringof);
}
Why don't you like a cleaner (in my opinion) solution?
class T() {
// Base class
int x;
}
class T(A...) : T!(A[0..$-1]) {
static if (A[$-1] == "Animal")
{
int y;
} else
static if (A[$-1] == "Dog")
{
int z;
} else
static if (A[$-1] == "Pug")
{
int s;
} else static assert(A[$-1]~" not a defined class of
"~this.stringof);
}