www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17771] New: foreach over const input range fails


          Issue ID: 17771
           Summary: foreach over const input range fails
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: alex.goltman gmail.com

    static struct NumRange {
        int front = 0;
        int end = 0;

         property auto length() const { return end - front; }
         property bool empty() const { return length == 0; }
        void popFront() { front++; }
    const r = NumRange(0, 5);
    foreach (x; r) {
results in
Error: mutable method test.main.NumRange.popFront is not callable using a const
even though foreach copies the input range it gets (as evident from running
foreach on same range twice), so it can at least try to copy it to an

Aug 21