On 8/13/21 11:04 AM, james.p.leblanc wrote:
>Dear All,
How does one use 'alias' to incorporate function arguments as well?
(I believe this is possible, from some of the examples of aliasSeq, and
the traits.Parameters documentation. However, I was unable to come up
with anything that works.)
What should replace the question marks (???) below?
>double bar( int a, double x){
return a*x:
}
template foo(T){
static if ( is(T==int) ){
alias ??? = ???
}
else{
alias ??? = ???
}
}
// when T == int, I desire the aliasing to produce resulting code:
foo( int a) = bar( int a, 42.33);
// when T == double, I desire:
foo( double x) = bar( 7, x);
Thanks kindly for any information!
James
PS I am aware of the "struct holding a function allowing multiple dispatch concept"
... while that would fit quite okay here in my simple example, it isn't appropriate
for my real use.
There isn't a way to alias it. You can wrap it though, and hope the inliner takes care of the difference:
auto foo(T)(T arg)
{
static if(is(T == int)) return bar(arg, 42.33);
else return bar(7, arg);
}
-Steve