On Tuesday, 6 August 2013 at 09:53:33 UTC, Ali Çehreli wrote:
Do you mean that when P[0] is already an instance of A, then R
should be P[0]. Otherwise, R should be A!P? If so, the
following works:
class A(P...)
{
pragma(msg, "\nA: " ~ P.stringof);
}
class BImpl(R, P...)
{
pragma(msg, "R: " ~ R.stringof ~ ", P: " ~ P.stringof);
}
template B(P...)
{
static if (is (P[0] == A!U, U)) {
/* The first type is already an A instance. Accept the
types as is. */
alias B = BImpl!P;
} else {
/* The first type is not an A instance. Inject one. */
alias B = BImpl!(A!P, P);
}
}
void main()
{
auto b0 = new B!(int, double, char);
auto b1 = new B!(A!long, int, double);
}
Ali
Great! Thanks Ali.