template with more than one tuple parameter

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 29 09:47:56 PDT 2012


On Sun, 29 Jul 2012 16:13:03 +0200, Timon Gehr <timon.gehr at gmx.ch> wrote:

> 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.
[snip]
> with(Test!(int,double,,float)){
[snip]
> Of course, that feels a little bolt-on. The alternative would be to
> accept that templates with multiple tuple parameters cannot be
> instantiated explicitly.

Indeed it does. We would do well to adopt another symbol than the comma,
I think. I thought for a moment foo!((int, float), (string, char)) could
work, as the comma operator is not defined to work on types. THe problem
appears when one tries to do the same with values: foo!((2,3), (4,5))
would be interpreted as foo!(3,5). Conceivably, one could simply allow
this syntax for type tuples.

Anyway, what other syntaxes do we have with a comma-separated list
and something else? Oh, foreach.

foreach (i, e; range) {}

foo!(int, float; string, char);

That's clearer, I think. And probably the best we get without breaking
other syntaxen.


-- 
Simen


More information about the Digitalmars-d-learn mailing list