non-lambda overloads for lambda-only things

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 15 22:02:10 UTC 2021


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

What the hell is the "fun length"? This is not FUN!!!

In any case, I thought of maybe adding something like this:

void map()(...) {
    static assert(false, "You didn't mean to do this. Make your lambda a 
template parameter");
}

To instead get a better error message:

Error: static assert:  "You didn't mean to do this. Make your lambda a 
template parameter"

  Is this worth adding to Phobos?

-Steve


More information about the Digitalmars-d mailing list