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,15 +463,17 @@ class Vector {
|
|||
/// Equality operator
|
||||
/// @param other the other vector
|
||||
/// @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();
|
||||
if (len == other.Length()) {
|
||||
if (len != other.Length()) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if ((*this)[i] != other[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -479,7 +481,10 @@ class Vector {
|
|||
/// @param other the other vector
|
||||
/// @returns true if this vector is not the same length as `other`, or all elements are not
|
||||
/// 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:
|
||||
/// Friend class (differing specializations of this class)
|
||||
|
|
|
@ -2060,6 +2060,15 @@ TEST(TintVectorRefTest, ConstBeginEnd) {
|
|||
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 tint::utils
|
||||
|
||||
|
|
Loading…
Reference in New Issue