On 04/06/2017 10:43 PM, ANtlord wrote:
Hello! I've got an issue related to making a Tuple or AliasSeq using
income template arguments. I want to create template makes an array of
objects from array of arrays have different sizes and different types of
values.

Here is a solution:

auto objectFactory(ObjectType, Args...)(Args args) {
    import std.algorithm : cartesianProduct, map;
    import std.array : array;

    return cartesianProduct(args).map!(a => ObjectType(a.expand)).array;
}

struct Pair {
    int number;
    string name;
}

import std.stdio;

void main() {
    auto pairKit = objectFactory!(Pair)([1, 2], ["qwe", "asd"]);
    auto pairSet = pairKit;
    writeln(pairSet);
}

Ali

Reply via email to