Bug 6798 – Integrate overloadings for multidimentional indexing and slicing
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-09T17:34:00Z
Last change time
2014-08-15T22:10:11Z
Keywords
patch
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2011-10-09T17:34:56Z
The following replacement has been proposed by issue 3474.
x[$-2, y[$-6, $-9], $-2]
// is translated to
// x.opIndex(x.opDollar!0 - 2,
// y.opIndex(y.opDollar!0 - 6, y.opDollar!1 - 9),
// x.opDollar!2 - 2)
Similarly, I propose the following replacement for the overloading mixture of indexing and slicing.
x[2..$, $-1, y[$-6, 0..$]]
// is translated to
// x.opIndex(x.opSlice!0(2, x.opDollar!0),
// x.opDollar!1 - 1,
// y.opIndex(y.opDollar!0 - 6, y.opSlice!1(0, y.opDollar!1)))
And additionally, I propose to merge slicing into indexing.
x[]
// is translated to
// x.opIndex()
After all, the indexing and slicing getter will be translated to x.opIndex(...), and the setter will be translated to x.opIndexAssign(value, ...).
And also, opSlice and opSliceAssign would be unnecessary.
Comment #1 by bearophile_hugs — 2011-10-09T19:55:28Z
So is this:
y[$-6, 0..$:2]
getting translated like this?
y.opIndex(y.opDollar!0 - 6, y.opSlice!1(0, y.opDollar!1, 2))
Strides/steps are sometimes useful in numerics code.