Closed rtbo closed 9 years ago
the expression arr[0..5, 0..2] triggers a syntax error, expecting a CLOSE_BRACKET token after the 5. This expression is however accepted by the compiler starting on 2.066.
arr[0..5, 0..2]
complete working code (error on line 83):
struct slice { uint start; uint size; } struct Example { int[] array; uint rows; uint cols; uint start; uint stride; this(int[] array, uint rows, uint cols, uint start=0, uint stride=uint.max) { this.array = array; this.rows = rows; this.cols = cols; this.start = start; this.stride = stride == uint.max ? cols : stride; } uint opDollar(uint dim)() { static assert(dim <= 1); static if (dim == 0) return rows; else return cols; } slice opSlice(uint Dim)(uint from, uint to) { return slice(from, to-from); } int opIndex(uint r, uint c) { return array[start + r*stride + c]; } // int[] opIndex(slice rs, uint c) { // // ... // } // int[] opIndex(uint r, slice cs) { // // ... // } Example opIndex(slice rs, slice cs) { uint r = rs.size; uint c = cs.size; uint s = start + rs.start*stride + cs.start; return Example(array, r, c, s, stride); } } int main() { auto m = Example([ 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44, 51, 52, 53, 54 ], 5, 4); assert (m[3, 2] == 43); auto m2 = m[slice(2, 3), slice(2, 2)]; assert (m2[1, 0] == 43); assert (m2.rows == 3 && m2.cols == 2); // m3 refers to the same slice as m2 auto m3 = m[2..5, 2..4]; // <- DDT syntax error is here assert (m3[1, 0] == 43); assert (m3.rows == 3 && m3.cols == 2); return 0; }
the expression
arr[0..5, 0..2]
triggers a syntax error, expecting a CLOSE_BRACKET token after the 5. This expression is however accepted by the compiler starting on 2.066.complete working code (error on line 83):