On 08/05/2013 11:45 AM, kdmult wrote:

> Hi,
>
> I would like to use a tuple template parameter in the default value of
> another template parameter in the same class declaration as follows.
>
> class A(P...) {}
>
> class B(R = A!P, P...) {}
>
> P... should be rightmost, so how can I use it in the preceding parameter?
>
> Thanks.

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

Reply via email to