On Friday, 7 April 2017 at 07:46:40 UTC, Ali Çehreli wrote:

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

It's great! Thanks a lot!

Reply via email to