December 17, 2019 range code doesn't work for multi-array | ||||
---|---|---|---|---|
| ||||
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)` |
December 17, 2019 Re: range code doesn't work for multi-array | ||||
---|---|---|---|---|
| ||||
Posted in reply to AlphaPurned | 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 |
Copyright © 1999-2021 by the D Language Foundation