Referencing an overloaded function

Artur Skawina art.08.09 at gmail.com
Sat Mar 24 11:51:53 PDT 2012


On 03/24/12 18:07, Artur Skawina wrote:
> On 03/24/12 15:39, Mantis wrote:
>> Will not hold for return types other than void, there may be some generic workaround (of course, you can pass return type as tempate parameter).
> 
> Something like
> 
>> auto getOverload(alias func, A...)(A a) {
>>     typeof(foo(a)) function(A) getOverload = &func;
>> }
> 
> would work.
> 
> The problem with that solution is however that .mangleof will return
> the wrong name.

Of course that should have been something more like:

> template tr(A...) { extern A tr; }
> template getOverload(alias func, A...) {
>     typeof(foo(tr!A)) function(A) getOverload = &func;
> }

and I should actually test the code before posting, even when the compiler
tries to make things difficult (Error: functions cannot return a tuple). ;)
While this version works now, it's still prevents getting the correct 
mangled function name - the getOverloads loop approach gets that right.

artur


More information about the Digitalmars-d-learn mailing list