Issue 20555 - Request to add trait matching to __traits(getOverloads, ...) to std.traits library module
Summary: Request to add trait matching to __traits(getOverloads, ...) to std.traits li...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-01 08:56 UTC by Uranuz
Modified: 2024-12-01 16:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Uranuz 2020-02-01 08:56:10 UTC
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 dlangBugzillaToGithub 2024-12-01 16:36:16 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10405

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB