If I have a function `foo` which has multiple template overloads, which might be alised, whatever. And I call it using `foo(1, "hi", x, SomeEnum.y)`, the compiler can figure out what I meant using IFTI, and call the right symbol.
But to *identify* that symbol is nearly impossible. It's not just `foo!(typeof(1), typeof("hi"), typeof(x), typeof(SomeEnum.y))` because templates allow all kinds of pattern matching and default values. In order to inspect the parameter types, you need to first *instantiate* the template, which is impossible. IFTI does this because it has insider knowledge!
I propose adding a mechanism to search for an overload using an expression.
__traits(getOverload, expression)
Where expression is an expression that is a function call (this is a requirement), which would provide the exact symbol for overload that would be called if the expression was executed.
So for example:
```d
void foo(size_t x = size_t.max, T)(T val) if(is(T == int)) {}
void foo(T)(T val) if(is(T == string)) {}
static assert(__traits(isSame(__traits(getOverload, foo(1)), foo!(size_t.max, int)));
static assert(__traits(isSame(__traits(getOverload, foo("hi")), foo!string));
```
Comment #1 by snarwin+bugzilla — 2024-02-27T18:30:32Z
+1, this would be a really useful addition.
I think the name __traits(getOverload) is probably too close to the existing __traits(getOverloads). Maybe something like __traits(selectedOverload) instead?
Comment #2 by robert.schadek — 2024-12-13T19:33:33Z