[Issue 20964] New: poor CTFE support for backward pointer (iterator) iteration
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 21 03:12:07 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20964
Issue ID: 20964
Summary: poor CTFE support for backward pointer (iterator)
iteration
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: blocker
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ilyayaroshenko at 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
prohibited.
```
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
[0..3]`
p++;
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
retroStart--;
}
This case is a reduced use case for generic retro iterators of Mir. Ranges
can't be used for this case.
--
More information about the Digitalmars-d-bugs
mailing list