Variadic grouping

JS js.mdnq at gmail.com
Sat Aug 10 05:40:53 PDT 2013


On Saturday, 10 August 2013 at 10:19:34 UTC, John Colvin wrote:
> On Monday, 29 July 2013 at 13:23:23 UTC, JS wrote:
>> Sometimes it's nice to be able to have groups of variadic 
>> parameters:
>>
>> template t(T1..., T2...)
>>
>> ...
>>
>> t!(a, b, c; d, e, f);
>>
>> so that a,b,c are for T1 and d,e,f are for T2.
>>
>> This can be done by making a symbol and breaking up a single 
>> variadic but is messy.
>>
>> I doubt such a feature will ever get added but who knows...
>
> I was initially unimpressed, but after some recent work I would

And this is why just because something looks "unimpressive" to 
you doesn't mean it is... Obviously if you've never run up 
against the specific problems proposed by people you won't know 
how frustrating it is, specially when there is an easy fix. This 
is why those commie bastards that shoot suggestions down at first 
sight ruin progress... they don't have the experience with the 
specific issue to know just how much it sucks.

> really like this feature. I have been using
>   struct Group(T...)
>   {
>       alias Ungroup = T;
>   }
> but, useful as it is, this feels like something that should 
> have some sugar on it.
>
>   template A(T0 ..., T1 ...)
>   {
>   // use T0 & T1
>   }
>
>   A!(int, long, double; Point, int)
>
> is so much nicer than
>

EXACTLY! Why the hell would I want to go around doing the stuff 
below all the time when there is a perfectly fine notation(above) 
for it? Just because deadlinx, or dicebot, or whoever wants to be 
close minded about it because they themselves haven't constantly 
ran into the issue.

It's very easy to write off someone elses issues because you 
yourself don't have the problems but it shows a lot of arrogance.

>   template A(T0, T1)
>   if(isGroup!T0 && isGroup!T1)
>   {
>       alias t0 = T0.Ungroup;
>       alias t1 = T1.Ungroup;
>
>       //use t0 && t1
>   }
>
>   A!(Group!(int, long, double), Group!(Point, int))

Even better, you can use something like A!(int, long, double, 
_S_, Point, int)

where _S_ acts as the `;`. Not great, but in my opinion it is 
simpler than the grouping and ungrouping. (you can write a 
utility function to convert between them).


More information about the Digitalmars-d mailing list