staticMap but with two arguments

John Chapman john.chapman at live.com
Wed Feb 8 20:04:19 UTC 2023


On Monday, 6 February 2023 at 09:17:07 UTC, Ali Çehreli wrote:
> I adapted staticMap's implementation to two sets of arguments:

So I've got this implementation, but wonder if I can generalise 
the arg splitting portion rather than write it manually for each 
N?

```d
template staticMapN(size_t N, alias fun, args...) if (args.length 
% N == 0) {
   alias staticMapN = AliasSeq!();
   static foreach (i; 0 .. args.length / N)
     static if (N == 1)
       staticMapN = AliasSeq!(staticMapN, fun!(args));
     else static if (N == 2)
       staticMapN = AliasSeq!(staticMapN, fun!(args[0 .. $ / 
N][i], args[$ / N .. ($ / N) * 2][i]));
     else static if (N == 3)
       staticMapN = AliasSeq!(staticMapN, fun!(args[0 .. $ / 
N][i], args[$ / N .. ($ / N) * 2][i], args[($ / N) * 2 .. ($ / N) 
* 3][i]));
     // etc
}
```


More information about the Digitalmars-d-learn mailing list