To take the full advantage of this optimization, a change in lambda function parameter type inference might be necessary, which sadly would be a breaking change:

struct S
{
    int get()
    {
        return 11;
    }

    int get() const
    {
        return 22;
    }
}

void main()
{
    S s;
    int n = (a) { return a.get(); }(s); // [1]
    writeln(n); // [2]
}

[1]: I think this lambda instantiates to something like:
int __fun(S a) { return a.get(); }
...but it'd be better if it first attempted to instantiate to:
int __fun(const S a) { return a.get(); }
...and resort to passing by mutable value only if the first attempt fails.

[2]: Currently prints 11, but would print 22 if this breaking change were made.

Reply via email to