I consider that current way of getting overloads list for symbol is ugly. Currently using __traits directly (as far as I understand) is considered as mean of last resort by much of the programmers. And is not a very good practice.
Let's look how we usually get overloads in some generic code:
void foo(string param1) {}
void foo(string param1, int param2, bool param3) {}
template Bar(alias Func)
{
alias Bar = __traits(getOverloads, __traits(parent, Func), __traits(identifier, Func));
}
The problemme is that whan I already have direct alias for symbol I need to do completelly useless and unnecessary steps to get `parent` of symbol and get it's identifier. So compiler maybe calculates alias for symbol again which could be less effective (but it's just assumption) /
I believe that we need a simple way to get overloads with template in std.traits.
I request the following simple signature:
template GetOverloads(alias symbol)
{
// whatever
}
The extra question is related to using __trait(getOverloads, ...) with symbols like lambda functions. Let's consider this example:
template Bar(alias Func) {
alias Bar = __traits(getOverloads, __traits(parent, Func), __traits(identifier, Func));
}
alias Test = Bar!(() { return `test`; });
This doesn't compile, because seems that it cannot get access to lamda for some reason:
//----
onlineapp.d(4): Error: no property __lambda1 for type void
onlineapp.d(4): Error: main().__lambda1 cannot be resolved
onlineapp.d(9): Error: template instance onlineapp.Bar!(function () pure nothrow @nogc @safe => "test") error instantiating
//----
I know that lambda usually cannot have any overloads, because unique name is created internally to every lambda. So it just always has 1 overload. But lamda is still a function, so it's expected that it should be treated the same way as others. It is not very convenient to write come generic code if I need to do extra special handling for lambda in this case. Everything should `just work`.
Thanks...
Comment #1 by robert.schadek — 2024-12-01T16:36:16Z