Infer return type from assignment

Adam D. Ruppe destructionator at gmail.com
Wed Apr 11 14:33:06 UTC 2018


On Wednesday, 11 April 2018 at 14:26:53 UTC, ixid wrote:
> Is it possible to infer a template's return type from what it's 
> assigned to? If not is this a difficult or worthless feature to 
> add?

Not really. The function call needs to make sense by itself:

fun(a)

needs to be a complete thing for a lot of things in the language 
to work. Type checking assumes it is there, inference assumes it 
is there, overloading assumes it s there, etc.

void foo(int);
void foo(float);

foo(fun(a)); // what happens?


So I don't say anything is impossible that isn't a paradox... but 
the effort level to solve all these problems would be really high 
for D.


More information about the Digitalmars-d-learn mailing list