Skip to content

Commit b0a8598

Browse files
committed
fix field for FieldIterators
1 parent 3a050fa commit b0a8598

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

source/mir/ndslice/iterator.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,18 +813,18 @@ struct FieldIterator(Field)
813813
static alias __map(alias fun) = FieldIterator__map!(Field, fun);
814814

815815
///
816-
_Slice!() opSlice()(size_t a, size_t b)
816+
_Slice!() opSlice(size_t dimension)(size_t i, size_t j) const
817817
{
818-
return typeof(return)(a, b);
818+
return typeof(return)(i, j);
819819
}
820820

821821
/++
822822
Returns:
823-
`_field[slice.i .. slice.j]`.
823+
`_field[_index + sl.i .. _index + sl.j]`.
824824
+/
825-
auto opIndex()(_Slice!() slice)
825+
auto opIndex()(_Slice!() sl)
826826
{
827-
return _field[_index + slice.i .. _index + slice.j];
827+
return _field[_index + sl.i .. _index + sl.j];
828828
}
829829

830830
auto ref opUnary(string op : "*")()

source/mir/ndslice/slice.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,24 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
796796
}
797797
}
798798

799+
///
800+
unittest
801+
{
802+
auto arr = [1, 2, 3, 4];
803+
auto sl0 = arr.sliced;
804+
auto sl1 = arr.slicedField;
805+
806+
assert(sl0.field is arr);
807+
assert(sl1.field is arr);
808+
809+
arr = arr[1 .. $];
810+
sl0 = sl0[1 .. $];
811+
sl1 = sl1[1 .. $];
812+
813+
assert(sl0.field is arr);
814+
assert(sl1.field is arr);
815+
}
816+
799817
/++
800818
Returns: static array of lengths
801819
See_also: $(LREF .Slice.structure)

0 commit comments

Comments
 (0)