Return type deduction

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 5 05:43:41 PDT 2016


On Monday, 5 September 2016 at 11:51:23 UTC, Lodovico Giaretta 
wrote:
> I see just one problem in this request:
>
> ===========================
> T get(T = int)()
> {
>     return T.init;
> }
>
> double val = get(); // should this call get!double or try to 
> call get!int and give an error?
> ===========================
>
> That is, what takes precedence? Default argument or inference 
> from the destination type? I'd personally prefer this to give 
> an error, as it is ambiguous and error prone.

I think it should be get!int(). It seems logical and it doesn't 
break existing code.



More information about the Digitalmars-d mailing list