template with more than one tuple parameter

Timon Gehr timon.gehr at gmx.ch
Sun Jul 29 07:13:03 PDT 2012


On 07/28/2012 06:47 PM, Simen Kjaeraas wrote:
> On Sat, 28 Jul 2012 18:17:14 +0200, Zhenya <zheny at list.ru> wrote:
>
>> Why do not D allow templates with more than one tuple
>> parameters,at the
>> same time that C++11 support it:
>
> Well, Walter implemented type tuples with automatic flattening,

The lack of multiple tuple parameters is not caused by automatic
flattening.

However, if they are introduced, the respective templates may only
ever be instantiated by IFTI.

To fix this, there would maybe need to be a special syntax to separate
the tuple parameters in an explicit instantiation, eg.

template Seq(T...){ alias T Seq; }

template Test(T..., S...){ alias T A; alias S B; }

with(Test!(int,double,float)){
     static assert(is(A==Seq!(int,double,float)));
     static assert(is(B==Seq!()));
}

with(Test!(int,double,,float)){
     static assert(is(A==Seq!(int,double)));
     static assert(is(B==Seq!(float)));
}

with(Test!(,int,double,float)){
     static assert(is(A==Seq!()));
     static assert(is(B==Seq!(int,double,float)));
}

Of course, that feels a little bolt-on. The alternative would be to
accept that templates with multiple tuple parameters cannot be
instantiated explicitly.


( If we want arbitrary tuple nesting, the notation could be
generalized, eg like this:

Seq!(Seq!(int,double)); // flattened 2-element tuple
Seq!(int,double,,); // 1-element tuple of 2-element tuple
Seq!(int,double,,,); // 1-element tuple of 1-element tuple of 2-element 
tuple
Seq!(int,double,,int,double); // 2-element tuple of 2-element tuples
  )


More information about the Digitalmars-d-learn mailing list