More templated type argument inference

Maxim Fomin maxim at maxim-fomin.ru
Thu Dec 6 06:41:50 PST 2012


On Thursday, 6 December 2012 at 13:04:05 UTC, bearophile wrote:
> Currently this code is not supported:
>
> void foo(T)(T x, T function(T) f) {}
> void main() {
>     foo(1, (int a) => a * a); // OK
>     foo(1, a => a * a);       // Error
> }
>

I forgot there is int here, so T in lambda should be deduced as 
int as well.

>
> With the latest alpha compiler it gives:
>
> test.d(4): Error: template test.foo does not match any function 
> template declaration. Candidates are:
> test.d(1):        test.foo(T)(T x, T function(T) f)
> test.d(4): Error: template test.foo(T)(T x, T function(T) f) 
> cannot deduce template function from argument types 
> !()(int,void)
>
>
> Do you think it's a good idea to allow it?
>
> Bye,
> bearophile

Does makes sense.


More information about the Digitalmars-d-learn mailing list