Parameters of overloaded templated function

Tejas notrealemail at gmail.com
Tue May 10 03:18:14 UTC 2022


On Tuesday, 10 May 2022 at 01:00:24 UTC, frame wrote:
> So `__traits(getOverloads)` returns also templated members and 
> `__traits(isTemplate)` can select those members. Unfortunately, 
> `Parameters!` does not work with the templated member. How can 
> I pass a symbol of T or A... to `Parameters!` as desired type 
> without instantiating the template?
>
> ```d
> fun(T, A...)(T arg, string foo, int bar, A args); // some 
> overload
> ```
>
> Assuming T is just an `int`, I cannot apply this type. The 
> compiler is forgetting the actual overload:
>
> ```d
> template getParams(alias overload) {
>   static if (__traits(isTemplate, overload)) {
>     alias typed = overload!int // error: fun(...) matches more 
> than one template declaration
>     alias getParams = Parameters!typed;
>   }
> }
> ```

Can you try
```d
template getParams(alias overload) {
   static if (__traits(isTemplate, overload)) {
     //alias typed = overload!int // error: fun(...) matches more 
than one template declaration
     alias getParams = Parameters!(overload!int); //don't use 
alias, send the argument directly
   }
}
```



More information about the Digitalmars-d-learn mailing list