non-lambda overloads for lambda-only things

Jacob Carlborg doob at me.com
Fri Apr 16 11:23:07 UTC 2021


On 2021-04-16 00:02, Steven Schveighoffer wrote:
> Have you ever written something like:
> 
> auto str = "hello".map(r => r.toUpper).array;
> 
> and been confronted with fun errors like:
> 
> Error: template std.algorithm.iteration.map cannot deduce function from 
> argument types !()(string, void), candidates are:
> /dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(479): 
>       map(fun...)
>   with fun = ()
>   must satisfy the following constraint:
>        fun.length >= 1

Yes, definitely. I doesn't help when there are longer chains and they're 
nested. It usually results in even more cryptic error messages.

BTW, what's stopping us from supporting the above syntax? Why do we 
still pass the lambda as a template argument? In that past, before 
proper support for lambdas, there was a use case to pass a string 
literal, which must be passed as a template argument. If DMD cannot 
inline the lambda, who cares, use LDC instead.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list