[llvm] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)
Utkarsh Saxena via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 04:58:39 PST 2023
https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/72348
>From b29aa485f2a541243d3764f4ed711ccc5a869519 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 15 Nov 2023 06:26:19 +0100
Subject: [PATCH 1/2] [STLExctras] Add out-of-line definition of friend
operator== for C++20
---
llvm/include/llvm/ADT/STLExtras.h | 40 +++++++++++++++++++++++--------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 18bc4d108b156bf..380d4d461c4e8db 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1291,16 +1291,19 @@ class indexed_accessor_range_base {
}
/// Compare this range with another.
- template <typename OtherT>
- friend bool operator==(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
- }
- template <typename OtherT>
- friend bool operator!=(const indexed_accessor_range_base &lhs,
- const OtherT &rhs) {
- return !(lhs == rhs);
- }
+ // FIXME: Make me a member function instead of friend when it works in C++20.
+ template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
+ typename PointerT2, typename ReferenceT2>
+ friend bool
+ operator==(const indexed_accessor_range_base<DerivedT2, BaseT2, T2, PointerT2,
+ ReferenceT2> &lhs,
+ const OtherT &rhs);
+ template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
+ typename PointerT2, typename ReferenceT2>
+ friend bool
+ operator!=(const indexed_accessor_range_base<DerivedT2, BaseT2, T2, PointerT2,
+ ReferenceT2> &lhs,
+ const OtherT &rhs);
/// Return the size of this range.
size_t size() const { return count; }
@@ -1364,6 +1367,23 @@ class indexed_accessor_range_base {
/// The size from the owning range.
ptrdiff_t count;
};
+
+// FIXME: Make me a member function instead of friend when it works in C++20.
+template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
+ typename PointerT2, typename ReferenceT2>
+bool operator==(const indexed_accessor_range_base<DerivedT2, BaseT2, T2,
+ PointerT2, ReferenceT2> &lhs,
+ const OtherT &rhs) {
+ return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
+ typename PointerT2, typename ReferenceT2>
+bool operator!=(const indexed_accessor_range_base<DerivedT2, BaseT2, T2,
+ PointerT2, ReferenceT2> &lhs,
+ const OtherT &rhs) {
+ return !(lhs == rhs);
+}
} // end namespace detail
/// This class provides an implementation of a range of
>From 064de694fb512a16005283bb140feb5f87138a6c Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Wed, 15 Nov 2023 13:58:18 +0100
Subject: [PATCH 2/2] remove friend declaration
---
llvm/include/llvm/ADT/STLExtras.h | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 380d4d461c4e8db..9f43bbc5b63a24b 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1290,21 +1290,6 @@ class indexed_accessor_range_base {
return (*this)[size() - 1];
}
- /// Compare this range with another.
- // FIXME: Make me a member function instead of friend when it works in C++20.
- template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
- typename PointerT2, typename ReferenceT2>
- friend bool
- operator==(const indexed_accessor_range_base<DerivedT2, BaseT2, T2, PointerT2,
- ReferenceT2> &lhs,
- const OtherT &rhs);
- template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
- typename PointerT2, typename ReferenceT2>
- friend bool
- operator!=(const indexed_accessor_range_base<DerivedT2, BaseT2, T2, PointerT2,
- ReferenceT2> &lhs,
- const OtherT &rhs);
-
/// Return the size of this range.
size_t size() const { return count; }
@@ -1367,8 +1352,8 @@ class indexed_accessor_range_base {
/// The size from the owning range.
ptrdiff_t count;
};
-
-// FIXME: Make me a member function instead of friend when it works in C++20.
+/// Compare this range with another.
+/// FIXME: Make me a member function instead of friend when it works in C++20.
template <typename OtherT, typename DerivedT2, typename BaseT2, typename T2,
typename PointerT2, typename ReferenceT2>
bool operator==(const indexed_accessor_range_base<DerivedT2, BaseT2, T2,
More information about the llvm-commits
mailing list