Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions source/mir/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,28 @@ public:
return ret;
}

static if (doUnittest)
///
@safe pure nothrow
version(mir_ndslice_test) unittest {
import mir.algorithm.iteration: equal;

immutable Slice!(int*, 1) x = [1, 2].sliced;
auto y = x.lightImmutable;
// this._iterator is copied to the new slice (i.e. both point to the same underlying data)
assert(x._iterator == y._iterator);
assert(x[0] == 1);
assert(x[1] == 2);
assert(y[0] == 1);
assert(y[1] == 2);
// Outer immutable is moved to iteration type
static assert(is(typeof(y) == Slice!(immutable(int)*, 1)));
// meaning that y can be modified, even if its elements can't
y.popFront;
// even if x can't be modified
//x.popFront; //error
}

/// Returns: Mutable slice over const data.
Slice!(LightConstOf!Iterator, N, kind, staticMap!(LightConstOf, Labels)) lightConst()() return scope const @property @trusted
{
Expand All @@ -997,6 +1019,26 @@ public:
return this.lightImmutable;
}

static if (doUnittest)
///
@safe pure nothrow
version(mir_ndslice_test) unittest {
import mir.algorithm.iteration: equal;

const Slice!(int*, 1) x = [1, 2].sliced;
auto y = x.lightConst;
// this._iterator is copied to the new slice (i.e. both point to the same underlying data)
assert(x._iterator == y._iterator);
assert(x.equal([1, 2]));
assert(y.equal([1, 2]));
// Outer const is moved to iteration type
static assert(is(typeof(y) == Slice!(const(int)*, 1)));
// meaning that y can be modified, even if its elements can't
y.popFront;
// even if x can't be modified
//x.popFront; //error
}

/// Label for the dimensions 'd'. By default returns the row label.
Slice!(Labels[d])
label(size_t d = 0)() @property
Expand Down