summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2018-06-28 11:45:28 +0000
committerPavel Labath <labath@google.com>2018-06-28 11:45:28 +0000
commit33aa5c546ec9eb2246c3ba83289c4bd01c4466e0 (patch)
treef18f0b2492a1e700e94f03c70924cdce1a1e6950
parent057ce39ea0eeb593e1f7483d297f9026d3be71bd (diff)
downloadbcm5719-llvm-33aa5c546ec9eb2246c3ba83289c4bd01c4466e0.tar.gz
bcm5719-llvm-33aa5c546ec9eb2246c3ba83289c4bd01c4466e0.zip
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
-rw-r--r--llvm/include/llvm/ADT/ArrayRef.h26
-rw-r--r--llvm/unittests/ADT/ArrayRefTest.cpp4
2 files changed, 14 insertions, 16 deletions
diff --git a/llvm/include/llvm/ADT/ArrayRef.h b/llvm/include/llvm/ADT/ArrayRef.h
index 9cb25b09c6c..4e97e9ca2de 100644
--- a/llvm/include/llvm/ADT/ArrayRef.h
+++ b/llvm/include/llvm/ADT/ArrayRef.h
@@ -273,6 +273,16 @@ namespace llvm {
}
/// @}
+ /// @name Comparison operators
+ /// @{
+
+ friend bool operator==(ArrayRef LHS, ArrayRef RHS) {
+ return LHS.equals(RHS);
+ }
+
+ friend bool operator!=(ArrayRef LHS, ArrayRef RHS) { return !(LHS == RHS); }
+
+ /// @}
};
/// MutableArrayRef - Represent a mutable reference to an array (0 or more
@@ -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>> {
diff --git a/llvm/unittests/ADT/ArrayRefTest.cpp b/llvm/unittests/ADT/ArrayRefTest.cpp
index e01d212f218..7f97c40d41c 100644
--- a/llvm/unittests/ADT/ArrayRefTest.cpp
+++ b/llvm/unittests/ADT/ArrayRefTest.cpp
@@ -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) {
OpenPOWER on IntegriCloud