Thread overview
Parameters of overloaded templated function
May 10, 2022
frame
May 10, 2022
Tejas
May 10, 2022
frame
May 10, 2022
frame
May 10, 2022
Tejas
May 10, 2022
frame
May 10, 2022
Mike Parker
May 10, 2022

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?

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:

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 10, 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?

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:

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

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 10, 2022

On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote:

>

Can you try

Makes 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:

>

Can you try

Makes no difference.

OK, I tried it in separate test and works. Weird, I already tried that before, there must be something wrong with my other template.

Thanks

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:

>

On Tuesday, 10 May 2022 at 03:18:14 UTC, Tejas wrote:

>

Can you try

Makes no difference.

OK, I tried it in separate test and works. Weird, I already tried that before, there must be something wrong with my other template.

Thanks

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

alias getParams = Parameters!(typed);//add the parenthesis

Maybe it's not taking the stuff after the second ! when it substitutes the alias typed?

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 there

I have break it down to a static if after that the compiler gets confused:

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.md

No, 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.