Re: ReturnType and overloaded functions

2015-06-13 Thread ketmar via Digitalmars-d
On Fri, 12 Jun 2015 17:28:56 -0700, Ali Çehreli wrote: >>> 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

Re: ReturnType and overloaded functions

2015-06-13 Thread Artur Skawina via Digitalmars-d
On 06/13/15 01:25, Yuxuan Shui via Digitalmars-d 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? alias ReturnType(alias F, A...) = typeof(F(A.init)); artu

Re: ReturnType and overloaded functions

2015-06-13 Thread Yuxuan Shui via Digitalmars-d
On Saturday, 13 June 2015 at 05:14:00 UTC, Kenji Hara wrote: 2015-06-13 9:29 GMT+09:00 Idan Arye via Digitalmars-d < digitalmars-d@puremagic.com>: On Friday, 12 June 2015 at 23:26:00 UTC, Yuxuan Shui wrote: When there are multiple overloaded functions, whose return type will I get when I use

Re: ReturnType and overloaded functions

2015-06-12 Thread Ali Çehreli via Digitalmars-d
On 06/12/2015 06:44 PM, Freddy wrote: > Why not just use templates? The question is about overloaded functions. Ali

Re: ReturnType and overloaded functions

2015-06-12 Thread Kenji Hara via Digitalmars-d
2015-06-13 9:29 GMT+09:00 Idan Arye via Digitalmars-d < digitalmars-d@puremagic.com>: > On Friday, 12 June 2015 at 23:26:00 UTC, 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 >>

Re: ReturnType and overloaded functions

2015-06-12 Thread Freddy via Digitalmars-d
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

Re: ReturnType and overloaded functions

2015-06-12 Thread Idan Arye via Digitalmars-d
On Friday, 12 June 2015 at 23:26:00 UTC, 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? The return type of the first declared one: http://dpaste.dzfl

Re: ReturnType and overloaded functions

2015-06-12 Thread Ali Çehreli via Digitalmars-d
On 06/12/2015 05:04 PM, ketmar wrote: 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 par

Re: ReturnType and overloaded functions

2015-06-12 Thread ketmar via Digitalmars-d
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 curiou

Re: ReturnType and overloaded functions

2015-06-12 Thread Ali Çehreli via Digitalmars-d
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

ReturnType and overloaded functions

2015-06-12 Thread Yuxuan Shui via Digitalmars-d
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?