ReturnType and overloaded functions

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 12 16:32:37 PDT 2015


On 06/12/2015 04:25 PM, Yuxuan Shui wrote:
> When there are multiple overloaded functions, whose return type will I
> get when I use ReturnType? Is there a way I could choose a specific
> function by its parameter types?

I am curious about the answer myself but there is the workaround of 
passing the overload through a lambda:

import std.traits;

int foo(long)
{
     return 0;
}

short foo(byte)
{
     return 0;
}

void main()
{
     static assert(is (ReturnType!(() => foo(long.init)) == int));
     static assert(is (ReturnType!(() => foo(byte.init)) == short));
}

Ali



More information about the Digitalmars-d mailing list