1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

ADT: Move ArrayRef comparison operators into the class

Summary:
This allows the implicit ArrayRef conversions to kick in when e.g.
comparing ArrayRef to a SmallVector.

Reviewers: zturner, dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D48632

llvm-svn: 335839
This commit is contained in:
Pavel Labath 2018-06-28 11:45:28 +00:00
parent 1a03456a00
commit 5f377f23f4
2 changed files with 14 additions and 16 deletions

View File

@ -272,6 +272,16 @@ namespace llvm {
return std::vector<T>(Data, Data+Length);
}
/// @}
/// @name Comparison operators
/// @{
friend bool operator==(ArrayRef LHS, ArrayRef RHS) {
return LHS.equals(RHS);
}
friend bool operator!=(ArrayRef LHS, ArrayRef RHS) { return !(LHS == RHS); }
/// @}
};
@ -510,22 +520,6 @@ namespace llvm {
return MutableArrayRef<T>(data, length);
}
/// @}
/// @name ArrayRef Comparison Operators
/// @{
template<typename T>
inline bool operator==(ArrayRef<T> LHS, ArrayRef<T> RHS) {
return LHS.equals(RHS);
}
template<typename T>
inline bool operator!=(ArrayRef<T> LHS, ArrayRef<T> RHS) {
return !(LHS == RHS);
}
/// @}
// ArrayRefs can be treated like a POD type.
template <typename T> struct isPodLike;
template <typename T> struct isPodLike<ArrayRef<T>> {

View File

@ -188,6 +188,10 @@ TEST(ArrayRefTest, Equals) {
EXPECT_TRUE(AR1b.equals({3, 4, 5, 6}));
EXPECT_FALSE(AR1b.equals({2, 3, 4, 5, 6}));
EXPECT_FALSE(AR1b.equals({3, 4, 5, 6, 7}));
SmallVector<int, 8> V1{1, 2, 3, 4, 5, 6, 7, 8};
EXPECT_EQ(AR1, V1);
EXPECT_EQ(V1, AR1);
}
TEST(ArrayRefTest, EmptyEquals) {