Creating Tuple or AliasSeq

ANtlord via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 7 01:45:07 PDT 2017


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!


More information about the Digitalmars-d-learn mailing list