non-lambda overloads for lambda-only things
Steven Schveighoffer
schveiguy at gmail.com
Fri Apr 16 14:02:24 UTC 2021
On 4/16/21 7:23 AM, Jacob Carlborg wrote:
> 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.
>
It could possibly work, if you specify the type. But I haven't thought
about the ramifications. I want to avoid creating closures, and as you
say, inlining might be affected.
-Steve
More information about the Digitalmars-d
mailing list