Issue Turning Template into Variadic Template
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 31 10:43:38 PDT 2016
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);
}
More information about the Digitalmars-d-learn
mailing list