tint: Fix vector equality operator
Change-Id: Ic8e66016beb8fd6a3046beaccbb9c07acbd765d5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105260 Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
8d3d4f6fd1
commit
ab2fa8be87
|
@ -463,13 +463,15 @@ class Vector {
|
||||||
/// Equality operator
|
/// Equality operator
|
||||||
/// @param other the other vector
|
/// @param other the other vector
|
||||||
/// @returns true if this vector is the same length as `other`, and all elements are equal.
|
/// @returns true if this vector is the same length as `other`, and all elements are equal.
|
||||||
bool operator==(const Vector& other) const {
|
template <typename T2, size_t N2>
|
||||||
|
bool operator==(const Vector<T2, N2>& other) const {
|
||||||
const size_t len = Length();
|
const size_t len = Length();
|
||||||
if (len == other.Length()) {
|
if (len != other.Length()) {
|
||||||
for (size_t i = 0; i < len; i++) {
|
return false;
|
||||||
if ((*this)[i] != other[i]) {
|
}
|
||||||
return false;
|
for (size_t i = 0; i < len; i++) {
|
||||||
}
|
if ((*this)[i] != other[i]) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -479,7 +481,10 @@ class Vector {
|
||||||
/// @param other the other vector
|
/// @param other the other vector
|
||||||
/// @returns true if this vector is not the same length as `other`, or all elements are not
|
/// @returns true if this vector is not the same length as `other`, or all elements are not
|
||||||
/// equal.
|
/// equal.
|
||||||
bool operator!=(const Vector& other) const { return !(*this == other); }
|
template <typename T2, size_t N2>
|
||||||
|
bool operator!=(const Vector<T2, N2>& other) const {
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Friend class (differing specializations of this class)
|
/// Friend class (differing specializations of this class)
|
||||||
|
|
|
@ -2060,6 +2060,15 @@ TEST(TintVectorRefTest, ConstBeginEnd) {
|
||||||
EXPECT_EQ(vec_ref.end(), &vec[0] + 3);
|
EXPECT_EQ(vec_ref.end(), &vec[0] + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(TintVectorTest, Equality) {
|
||||||
|
EXPECT_EQ((Vector<int, 2>{1, 2}), (Vector<int, 2>{1, 2}));
|
||||||
|
EXPECT_EQ((Vector<int, 1>{1, 2}), (Vector<int, 3>{1, 2}));
|
||||||
|
EXPECT_NE((Vector{1, 2}), (Vector{1}));
|
||||||
|
EXPECT_NE((Vector{1}), (Vector{1, 2}));
|
||||||
|
EXPECT_NE((Vector{1, 2}), (Vector{2, 1}));
|
||||||
|
EXPECT_NE((Vector{2, 1}), (Vector{1, 2}));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::utils
|
} // namespace tint::utils
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue