www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7668] New: std.algorithm.reduce of array of const ints too


           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: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

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)

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