http://d.puremagic.com/issues/show_bug.cgi?id=7668

           Summary: std.algorithm.reduce of array of const ints too
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2012-03-07 20:09:38 PST ---
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)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to