function overload on full signature?

Rob T rob at ucora.com
Tue Nov 13 15:20:11 PST 2012


On Tuesday, 13 November 2012 at 21:37:38 UTC, Peter Alexander 
wrote:
> On Tuesday, 13 November 2012 at 21:34:28 UTC, Rob T wrote:
>> I'm wondering why overloading has been implemented to only 
>> match on the argument list rather than the full signature 
>> which includes the return type? I know I would use it if it 
>> was available.
>
> If it worked on return type, how would it decide the overload?
>
> int foo() { ... }
> string foo() { ... }
>
> void bar(int x) { ... }
> void bar(string y) { ... }
>
> auto z = foo(); // what foo?
> bar(foo()); // what foo?

Don't use auto in such cases. If the compiler cannot resolve 
ambiguity, it will issue an error telling you that you must 
resolve the situation with explicit typing. I don't see a 
problem, because this is similar to the situation we already have 
when you err and create two functions with the same argument sig, 
the compiler cannot tell which function to use and issues an 
error with appropriate message.

--rt




More information about the Digitalmars-d mailing list