www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20964] New: poor CTFE support for backward pointer (iterator)


          Issue ID: 20964
           Summary: poor CTFE support for backward pointer (iterator)
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: blocker
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ilyayaroshenko gmail.com

Pointer can refer to the next right element after memory block.
However, referring to the next left element before the memory block is

uint foo(uint[3] m)
        auto p = m.ptr;
    p += 3; // ok, p refers to the next element after block!
    p -= 4; // fails: `cannot assign pointer to index -1 inside memory block
    return *p;

static assert(foo([3, 2, 4]) == 3);

The use case:

uint* retroStart; // refers to the last element
uint length;

foreach (i; 0 .. length)
    // use *retroStart

This case is a reduced use case for generic retro iterators of Mir. Ranges
can't be used for this case.

Jun 20 2020