digitalmars.D.learn - range code doesn't work for multi-array
- AlphaPurned (7/7) Dec 16 2019 if arr is a single array the follow code works(removing [i]) but
- mipri (18/25) Dec 16 2019 The problem isn't that it's a multi-array but that it's a
if arr is a single array the follow code works(removing [i]) but if it is a double array it fails. arr as type double[A][B]. arr[i] has type double[A]. v ~= arr[i].map!(a=>to!string(a)~",").join; with `Range = double[21]` must satisfy the following constraint: ` isInputRange!(Unqual!Range)`
Dec 16 2019
On Tuesday, 17 December 2019 at 07:40:28 UTC, AlphaPurned wrote:if arr is a single array the follow code works(removing [i]) but if it is a double array it fails. arr as type double[A][B]. arr[i] has type double[A]. v ~= arr[i].map!(a=>to!string(a)~",").join; with `Range = double[21]` must satisfy the following constraint: ` isInputRange!(Unqual!Range)`The problem isn't that it's a multi-array but that it's a fixed-size array. As the error suggests: it complains about a double[21], and not about a double[][] Fixed size arrays you need to slice to make them valid input ranges. (std.container.array is the same.) At a terminal: $ rdmd --eval 'int[3] x; x.map!"a+1".writeln' ... with Range = int[3] whose parameters have the following constraints: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > isInputRange!(Unqual!Range) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tip: not satisfied constraints are marked with > $ rdmd --eval 'int[3] x; x[].map!"a+1".writeln' [1, 1, 1] Note the [] in x[].map
Dec 16 2019