Deducing a template retrun parameter type based on an assignment?

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 30 02:06:23 PST 2015


On Friday, 30 January 2015 at 08:52:41 UTC, bearophile wrote:
> Jeremy DeHaan:
>
>> I figured that it would be smart enough to
>> deduce the parameter type based on the type that it was trying 
>> to be assigned to.
>
> For that you need languages like Haskell/Rust. D type inference 
> doesn't work from the type something is assigned to.

But it could, right (for arguments and return expressions, too)? 
At least I don't see any real obstacles. Just file an enhancement 
request if you think it's worthwhile, or start a discussion on 
digitalmars.D.

Of course, it cannot work for `auto x = getString();` or 
`foo(getString())` where there are several overloads of `foo()`. 
The next step would then be overloading on the return type, which 
is related.


More information about the Digitalmars-d-learn mailing list