On Fri, 12 Jun 2015 16:32:37 -0700, Ali Çehreli wrote:

> 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

or without importing `std.traits`:

  static assert(is(typeof(foo(long.init)) == int));
  static assert(is(typeof(foo(byte.init)) == short));

Attachment: signature.asc
Description: PGP signature

Reply via email to