On Monday, 15 June 2015 at 13:44:53 UTC, Dennis Ritchie wrote:
On Monday, 15 June 2015 at 10:00:43 UTC, Ilya Yaroshenko wrote:
N-dimensional slices is ready for comments!
It seems to me that the properties of the matrix require `row`
and `col` like this:
import std.stdio, std.experimental.range.ndslice, std.range :
iota;
void main() {
auto matrix = 100.iota.sliced(3, 4, 5);
writeln(matrix[0]);
// [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]]
// writeln(matrix[0].row); // 4
// writeln(matrix[0].col); // 5
}
P.S. I'm not exactly sure that these properties should work
exactly as in my code :)
This works:
unittest {
import std.stdio, std.experimental.range.ndslice;
import std.range : iota;
auto matrix = 100.iota.sliced(3, 4, 5);
writeln(matrix[0]);
writeln(matrix[0].length); // 4
writeln(matrix[0].length!0); // 4
writeln(matrix[0].length!1); // 5
writeln(matrix.length!2); // 5
}
Prints:
//[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15,
16, 17, 18, 19]]
//4
//4
//5
I am note sure that we need something like `height`/row and
`width`/col for nd-slices. This kind of names can be used after
casting to the future `std.container.matrix`.