On Tuesday, 6 August 2013 at 05:07:51 UTC, Ali Çehreli wrote:
On 08/05/2013 09:51 PM, kdmult wrote:
On Monday, 5 August 2013 at 18:45:49 UTC, kdmult wrote:
class A(P...) {}

class B(R = A!P, P...) {}

P... should be rightmost, so how can I use it in the preceding parameter?

The default parameter value doesn't make sense as it's shown above.
Actually I want to port C++ code which looks like below.

template <typename P1>
class A1 {};
template <typename P1, typename R=A1<P1> >
class B1 {}

template <typename P1, typename P2>
class A2 {};
template <typename P1, typename P2, typename R=A2<P1,P2> >
class B2 {}

and so on.

I would use the variadic template parameters. However, I have no idea
how it can be done. Please advise.

Thanks.

Direct translation seems to work:

class A1(P1) {}
class B1(P1, R = A1!P1) {}

class A2(P1, P2) {}
class B2(P1, P2, R = A2!(P1, P2)) {}

void main()
{
    auto a1 = new A1!int;
    auto b1d = new B1!int;
    auto b1 = new B1!(int, A1!double);
    auto a2 = new A2!(int, double);
    auto b2d = new B2!(int, double);
    auto b2 = new B2!(int, double, A2!(char, short));
}

Ali

Is there a way to use variadic template/class parameter instead
of P1, P2, ..., PN ? If it is I could create 2 templated classes
instead of all that copy/pasted classes with P1, P2, etc
parameters.

Thanks.

Reply via email to