Variadic grouping

bearophile bearophileHUGS at lycos.com
Mon Jul 29 08:39:22 PDT 2013


> template Select(bool condition, T...)
> if (T.length == 2 && SameKind!T) {
>     static if (__traits(compiles, {enum x = T[0];})) {
>         static if (condition)
>             enum Select = T[0];
>         else
>             enum Select = T[1];
>     } else {
>         static if (condition)
>             alias Select = T[0];
>         else
>             alias Select = T[1];
>     }
> }

It works in simple cases and maybe it's worth changing in some 
way the Select of Phobos, to support values too.
But to solve the problem in general I think there's a need for 
"lazy template arguments", similar to lazy function arguments, 
but for types.

template Select(condition, lazy T1, lazy T2) {...}

Bye,
bearophile


More information about the Digitalmars-d mailing list