www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - range code doesn't work for multi-array

reply AlphaPurned <Alpha Beta.com> writes:
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
parent mipri <mipri minimaltype.com> writes:
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