Variadic grouping

Robert Clipsham robert at octarineparrot.com
Mon Jul 29 07:46:00 PDT 2013


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...

You can achieve this like so:
----
template Outer(T...) {
     template Inner(U...) {
         // Do something with T and U
     }
}
Outer!(a, b, c).Inner!(d, e, f);
----

You can see an example of it in action here (type tuple 
intersection):
https://github.com/mrmonday/misc/blob/master/misc/misc.d#L5

Robert


More information about the Digitalmars-d mailing list