When using 'each', you have to be careful not to use pass-by-value: ----- import std.algorithm; void main() { struct S { int x; } auto arr = [S(0), S(0), S(0), S(0)]; arr.each!(elem => elem.x = 1); // no-op, it was pass by value assert(arr != [S(1), S(1), S(1), S(1)]); arr.each!((ref elem) => elem.x = 1); // ok, this works assert(arr == [S(1), S(1), S(1), S(1)]); arr.each!(ref elem => elem.x = 1); // why not this syntax too? assert(arr == [S(1), S(1), S(1), S(1)]); } ----- It would be really cool if we could use the proposed syntax in the third call.
Dunno, delegates already have quite overloaded and ambiguous syntax.
*** Issue 20265 has been marked as a duplicate of this issue. ***
In the notation ref elem => elem.x = 1 it is unclear whether `ref` refers to the return value of the lambda or the parameter. These do work: (ref elem) => elem.x = 1 ref (elem) => elem.x = 1 (The second would be rejected because it returns a reference to a local.) I'll close this, please reopen if appropriate.