Question about alias and getOverloads
uranuz
neuranuz at gmail.com
Tue Jan 28 21:34:17 UTC 2020
I have read it two or three times just before writing my question:
https://dlang.org/spec/declaration.html#alias
And also a have read all the dlang docs several time few years
ago... ;)
But I don't see what do you you mean by writing that it was
menioned here. I don't se any words or any examples that describe
how `alias` works with function overload sets. Is it a blind
assumption that it was written here?
The only example that someone can mix up and consider as answer
to my question if actually didn't read it with attention. It is
example bellow:
```
alias myint = int;
void foo(int x) { ... }
void foo(myint m) { ... } // error, multiply defined function foo
```
But the only thing that this example illustrates is that `myint`
and `int` is actualy the same type. So this overload set is just
incorrect. I don't ask you to consider the case where overload
set is incorrect. So this didn't answered my question in any way.
Looks like this is some kind of nasty details that language
developers don't "proud of" and don't like to discover details
about how it's working. Or just lazy enough to do so ;)
Still I figured answer myself using your example. The answer is
not full, but yet enough for me for practical usage. But the lack
of description about it makes me think that I am not the last man
who will have his curiosity not fully satisfied about this aspect
of language.
And also __traits(parent, Func) seems like not universal for all
cases with functions, because it fails on lambda-functions. For
instance:
//----
import std;
template Bar(alias Func) {
alias Bar = __traits(getOverloads, __traits(parent, Func),
__traits(identifier, Func));
}
void main()
{
alias Test = Bar!(() { return `test`; });
}
//----
Output:
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
//----
Seems that it fails to get parent for lambda. I don't know why?
What parent should be for labmda?
Thanks for attention!
More information about the Digitalmars-d-learn
mailing list