digitalmars.D.learn - Parameters of overloaded templated function
- frame (19/19) May 09 2022 So `__traits(getOverloads)` returns also templated members and
- Tejas (12/32) May 09 2022 Can you try
- frame (2/3) May 10 2022 Makes no difference.
- frame (4/8) May 10 2022 OK, I tried it in separate test and works. Weird, I already tried
- Tejas (12/22) May 10 2022 Using aliases as parameters doesn't work(and the DIP that wanted
- frame (12/17) May 10 2022 I have break it down to a `static if` after that the compiler
- Mike Parker (5/8) May 10 2022 No, it wasn't rejected. The author decided it needed reworking
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; } } ```
May 09 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 } } ```
May 09 2022
On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote:Can you tryMakes no difference.
May 10 2022
On Tuesday, 10 May 2022 at 11:26:44 UTC, frame wrote:On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote:OK, I tried it in separate test and works. Weird, I already tried that before, there must be something wrong with my other template. ThanksCan you tryMakes no difference.
May 10 2022
On Tuesday, 10 May 2022 at 11:33:24 UTC, frame wrote:On Tuesday, 10 May 2022 at 11:26:44 UTC, frame wrote:Using aliases as parameters doesn't work(and the DIP that wanted to have this behaviour was de facto rejected) https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1023.md But considering you're passing it as an argument, not a formal parameter, it should've worked... Idk what's happening there Try ```d alias getParams = Parameters!(typed);//add the parenthesis ``` _Maybe_ it's not taking the stuff after the second `!` when it substitutes the alias `typed`?On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote:OK, I tried it in separate test and works. Weird, I already tried that before, there must be something wrong with my other template. ThanksCan you tryMakes no difference.
May 10 2022
On Tuesday, 10 May 2022 at 12:12:13 UTC, Tejas wrote:Using aliases as parameters doesn't work(and the DIP that wanted to have this behaviour was de facto rejected) https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1023.md But considering you're passing it as an argument, not a formal parameter, it should've worked... Idk what's happening thereI have break it down to a `static if` after that the compiler gets confused: ```d static if(__traits(isTemplate, overload)) { // compiler knows it is a template but error is something about an aliased function in further processing } ``` However, changing it to `isSomeFunction!overload` and just passing the type argument otherwise, compiles. Not very clean, though.
May 10 2022
On Tuesday, 10 May 2022 at 12:12:13 UTC, Tejas wrote:Using aliases as parameters doesn't work(and the DIP that wanted to have this behaviour was de facto rejected) https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1023.mdNo, it wasn't rejected. The author decided it needed reworking after one round of review, but he didn't have the time for it. So it was marked "Postponed". He was willing to turn it over to someone else, if anyone is interested.
May 10 2022