staticMap but with two arguments

John Chapman john.chapman at live.com
Mon Feb 6 01:20:06 UTC 2023


I have two AliasSeqs: one containing a function's parameters 
(SourceSeq), the other containing the types I want to convert 
said parameters to (TargetSeq). I'd use something like staticMap 
to call the conversion function with both a parameter from 
SourceSeq and a type from TargetSeq, and return an AliasSeq of 
converted values which will be forwarded to another function. 
staticMap's "fun" can only be instantiated with a single 
argument, while I need it to work with two.

E.g.:
```
template toTarget(alias source, Target) {
   static if (is(typeof(source) == int) && is(Target == string)) 
// for example, convert int to string
}

alias TargetSeq = Parameters!targetFunc;

auto wrapperFunc(A...)(A) {
   alias SourceSeq = __traits(parameters);
   return targetFunc(staticMap!(toTarget, SourceSeq)); // How 
would I call staticMap (or something similar) with SourceSeq 
*and* TargetSeq?
}
```

I could build the list of converted values manually but I wanted 
something smart (like staticMap) to do it inline. I thought 
ApplyLeft/Right could help but couldn't get my head around it.


More information about the Digitalmars-d-learn mailing list