Question about alias and getOverloads

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 30 19:43:45 UTC 2020


On Thu, Jan 30, 2020 at 06:20:47PM +0000, uranuz via Digitalmars-d-learn wrote:
[...]
> 1. Why API for __traits(getOverloads) is so strange. Why I need to
> find parent for symbol myself and pass actual symbol name as string,
> but not actually pass a symbol itself? It is very strange to me...

Actually, __traits was not intended to be used by end user code.  It's
supposed to be a raw, low-level interface into compiler internals, that
the standard library uses to implement a nicer user-facing API, i.e.,
std.traits.

Unfortunately, std.traits hasn't kept up with the proliferation of
__traits, and now we have pretty widespread use of __traits in user code
for doing things std.traits can't do, or can't do very well.

If you think __traits(getOverloads) is strange, wait till you see the
weird function parameter tuples that behave like tuples but actually
have extra information associated with them, but this information
"disappears" when you index the tuple or otherwise manipulate it like a
"normal" tuple.  Instead, to extract this information you must take
1-element slices of it.  Thankfully, this ugly mess is hidden behind
nicely-clothed citizens of std.traits, so user code rarely has to deal
with this craziness.

Arguably, any weird behaviours of __traits ought to be reason to file a
bug to add a nicer-behaving API to std.traits.  In fact, any __traits
that doesn't have a std.traits analogue arguably should be a bug.


> 2. Where in the documentation is mentioned that when I create alias to
> name that is a function or method that has overloads then this alias
> is actually an alias not only for the first or second or randomly
> selected overload in overload set, but an alias for all of overloads
> in set at the same time?
[...]

It's probably missing/incomplete documentation.  File a bug.


T

-- 
Change is inevitable, except from a vending machine.


More information about the Digitalmars-d-learn mailing list