Question about alias and getOverloads

uranuz neuranuz at gmail.com
Tue Jan 28 19:26:03 UTC 2020


Hello! I have a question about `alias` template parameter and 
getOverloads.
For instance I have some code like this:
// -----
import std;
import core.thread;

void foo(string param1) {}
void foo(string param1, int param2) {}

template Bar(alias Func)
{
     // Next line is not valid now. This is my understanding of 
how I wish it would work...
     pragma(msg, __traits(getOverloads, Func));
}

void main()
{
     Bar!foo;
}
//---
By the spec:
https://dlang.org/spec/traits.html#getOverloads
The signature of `getOverloads` trait requires me to pass a 
symbol where my function is contained (it could be class, struct 
or module). And a name of function that I want to get overloads 
for.

Let's imagine that `foo` overloads and Bar template are in 
different modules. And `Bar` template doesn't have no direct 
access to module where `foo` is contained. And `Bar` is 
instantiated outside module where `Bar` is declared.

I have two questions:
1. Whether `Bar` instantiation would get first, second or both 
overloads of function? Or maybe I would get two instantiations of 
template by the number of overloads? I don't understand well how 
this mechanic is working. Is it documented somewhere? Does 
actually one alias parameter represents only one symbol from 
overload set or all of them?

2. If alias parameter represents multiple symbols from overload 
set. Then I wish I could access to list of overloads having alias 
parameter. I wish to get count of overloads in my real case in 
order to issue an error that overloaded are not supported by my 
code.





More information about the Digitalmars-d-learn mailing list