a slice to create a view on.
A lazy slice with elements converted to the type T.
import mir.ndslice.slice: Slice; import mir.ndslice.allocation : slice; import mir.ndslice.topology : diagonal, as; auto matrix = slice!double([2, 2], 0); auto stringMatrixView = matrix.as!int; assert(stringMatrixView == [[0, 0], [0, 0]]); matrix.diagonal[] = 1; assert(stringMatrixView == [[1, 0], [0, 1]]); /// allocate new slice composed of strings Slice!(int*, 2) stringMatrix = stringMatrixView.slice;
Special behavior for pointers to a constant data.
import mir.ndslice.allocation : slice; import mir.ndslice.slice: Contiguous, Slice; Slice!(double*, 2) matrix = slice!double([2, 2], 0); Slice!(const(double)*, 2) const_matrix = matrix.as!(const double);
Ranges
import mir.algorithm.iteration: filter, equal; assert(5.iota.filter!"a % 2".as!double.map!"a / 2".equal([0.5, 1.5]));
Convenience function that creates a lazy view, where each element of the original slice is converted to the type T. It uses map and $(TT to) composition under the hood.