On 30.03.2016 20:12, jmh530 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. The latest thing I tried is:

auto mixedCartesianProduct(T...)(T x)
{
     import std.algorithm : cartesianProduct;

     foreach(t; x)
             t = conditionalOnly(t);

     return cartesianProduct(x);
}

auto mixedCartesianProduct(T...)(T x)
{
    import std.algorithm : cartesianProduct;
    import std.meta: staticMap;
    import std.traits : ReturnType;

    alias ConditionalOnly(T) = ReturnType!(conditionalOnly!T);
    alias RangeTypes = staticMap!(ConditionalOnly, T);

    RangeTypes ranges;
    foreach (i, t; x) ranges[i] = conditionalOnly(t);

    return cartesianProduct(ranges);
}

Reply via email to