import std.algorithm: reduce; void main() { const data = [2, 3, 4]; int r1 = reduce!q{a * b}(0, data); // OK int r2 = reduce!q{a * b}(data); // error } DMD 2.059head gives: ...\dmd2\src\phobos\std\algorithm.d(731): Error: can only initialize const member _field_field_0 inside constructor ...\dmd2\src\phobos\std\conv.d(3334): Error: *chunk is not mutable ...\dmd2\src\phobos\std\algorithm.d(743): Error: template instance std.conv.emplace!(const(int),const(int)) error instantiating test.d(5): instantiated from here: reduce!(const(int[])) test.d(5): Error: template instance std.algorithm.reduce!("a * b").reduce!(const(int[])) error instantiating I think reduce!q{a*b}(data) too should compile and work. -------------- Extra note: in std.algorithm.reduce there is also this (now bug 2443 is fixed) at about line 723: // For now, just iterate using ref to avoid unnecessary copying. // When Bug 2443 is fixed, this may need to change. foreach(ref elem; r) { if(initialized)
This appears to be have been fixed in 2.062 although I can't find the exact pull that fixed it.
Changed to WORKSFORME so that it doesn't appear in the changelog for next update.