Issue Turning Template into Variadic Template
Artur Skawina via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 31 03:27:41 PDT 2016
On 03/30/16 20:12, jmh530 via Digitalmars-d-learn wrote:
> I wrote a version of cartesianProduct that will return the cartesian product when the some of the types are not ranges. The original code is below.
>
> My issue is that I can't figure out how to turn it into a variadic template.
> auto mixedCartesianProduct(T, U)(T x, U y)
> {
> import std.algorithm : cartesianProduct;
>
> return cartesianProduct(conditionalOnly(x), conditionalOnly(y));
> }
auto mixedCartesianProduct(T...)(T x)
{
import std.range, std.algorithm : cartesianProduct;
return mixin(`cartesianProduct(`~iota(T.length).map!`"conditionalOnly(x["~text(a)~"])"`().join(",")~`)`);
}
artur
More information about the Digitalmars-d-learn
mailing list