[clang-tools-extra] [clang] [llvm] [STLExtras] Add out-of-line definition of friend operator== for C++20 (PR #72348)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 28 05:45:00 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/4] [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/4] 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,
>From c8d3c272564f0c8d2c43c501506913c7f05a3eda Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Thu, 16 Nov 2023 11:35:18 +0000
Subject: [PATCH 3/4] s/DerivedT2/DerivedT2
---
llvm/include/llvm/ADT/STLExtras.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 9f43bbc5b63a24b..ecaa7cce1522115 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1354,18 +1354,18 @@ class indexed_accessor_range_base {
};
/// 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,
- PointerT2, ReferenceT2> &lhs,
+template <typename OtherT, typename DerivedT, typename BaseT, typename T,
+ typename PointerT, typename ReferenceT>
+bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T,
+ PointerT, ReferenceT> &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,
+template <typename OtherT, typename DerivedT, typename BaseT, typename T,
+ typename PointerT, typename ReferenceT>
+bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T,
+ PointerT, ReferenceT> &lhs,
const OtherT &rhs) {
return !(lhs == rhs);
}
>From bd17e2125fa43feb447648d53136b8ebc7d58576 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena <usx at google.com>
Date: Thu, 16 Nov 2023 13:11:14 +0100
Subject: [PATCH 4/4] format
---
llvm/include/llvm/ADT/STLExtras.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index ecaa7cce1522115..a136eeb0ff1bd7c 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1356,16 +1356,16 @@ class indexed_accessor_range_base {
/// FIXME: Make me a member function instead of friend when it works in C++20.
template <typename OtherT, typename DerivedT, typename BaseT, typename T,
typename PointerT, typename ReferenceT>
-bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T,
- PointerT, ReferenceT> &lhs,
+bool operator==(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
+ ReferenceT> &lhs,
const OtherT &rhs) {
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template <typename OtherT, typename DerivedT, typename BaseT, typename T,
typename PointerT, typename ReferenceT>
-bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T,
- PointerT, ReferenceT> &lhs,
+bool operator!=(const indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,
+ ReferenceT> &lhs,
const OtherT &rhs) {
return !(lhs == rhs);
}
More information about the cfe-commits
mailing list