Skip to content
Closed
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
45 changes: 27 additions & 18 deletions std/experimental/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,9 @@ struct Slice(size_t _N, _Range)
bool opEquals(size_t NR, RangeR)(auto ref Slice!(NR, RangeR) rslice)
if (Slice!(NR, RangeR).PureN == PureN)
{
if (this._lengths != rslice._lengths)
return false;
foreach (i; Iota!(0, PureN))
if (this._lengths[i] != rslice._lengths[i])
return false;
static if (
!hasReference!(typeof(this))
&& !hasReference!(typeof(rslice))
Expand All @@ -1737,17 +1738,27 @@ struct Slice(size_t _N, _Range)
if (this._strides == rslice._strides && this._ptr == rslice._ptr)
return true;
}
return opEqualsImpl(this, rslice);
foreach (i; Iota!(0, PureN))
if (this._lengths[i] == 0)
return true;
import std.experimental.ndslice.selection : unpack;
return opEqualsImpl(this.unpack, rslice.unpack);
}

///ditto
bool opEquals(T)(T[] rarrary)
{
if (this.length != rarrary.length)
auto slice = this;
Copy link
Contributor

@JackStouffer JackStouffer Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind this? Why not just use this?

Copy link
Member Author

@9il 9il Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slice.popFront; will change the slice

if (slice.length != rarrary.length)
return false;
foreach (i, ref e; rarrary)
if (e != this[i])
if (rarrary.length) do
{
if (slice.front != rarrary.front)
return false;
slice.popFront;
rarrary.popFront;
}
while (rarrary.length);
Copy link
Contributor

@Hackerpilot Hackerpilot Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change also part of one of the other pull requests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes. Thank you! it is part of #4647

return true;
}

Expand Down Expand Up @@ -2765,28 +2776,26 @@ unittest
}

private bool opEqualsImpl
(size_t NL, RangeL, size_t NR, RangeR)(
auto ref Slice!(NL, RangeL) ls,
auto ref Slice!(NR, RangeR) rs)
in
{
assert(ls._lengths == rs._lengths);
}
body
(size_t N, RangeL, RangeR)(
Slice!(N, RangeL) ls,
Slice!(N, RangeR) rs)
{
foreach (i; 0 .. ls.length)
do
{
static if (Slice!(NL, RangeL).PureN == 1)
static if (Slice!(N, RangeL).PureN == 1)
{
if (ls[i] != rs[i])
if (ls.front != rs.front)
return false;
}
else
{
if (!opEqualsImpl(ls[i], rs[i]))
if (!opEqualsImpl(ls.front, rs.front))
return false;
}
rs.popFront;
ls.popFront;
}
while (ls.length);
return true;
}

Expand Down