summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-29 17:02:06 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-30 13:27:14 +0100
commit951274a9b9186ec9b840eb96bed99a501d3f214b (patch)
treedb5c7337854261e7ee2f9423f34f22760ecef0d4 /src
parentb0d4d95a2986595fda4a2cc8a163e44c9b4162a6 (diff)
Make QVarLengthArray comparisons hidden friends
Task-number: QTBUG-87975 Change-Id: Iaebb237b3d5d3e881caf9a93153e295af051e2ab Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qvarlengtharray.h117
1 files changed, 77 insertions, 40 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 0bbee4f36e..b538cf292d 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -310,6 +310,68 @@ public:
inline const T &back() const { return last(); }
void shrink_to_fit() { squeeze(); }
+#ifdef Q_QDOC
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+ template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
+ friend inline bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r);
+#else
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_eq_result<U> operator==(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
+ {
+ if (l.size() != r.size())
+ return false;
+ const T *rb = r.begin();
+ const T *b = l.begin();
+ const T *e = l.end();
+ return std::equal(b, e, QT_MAKE_CHECKED_ARRAY_ITERATOR(rb, r.size()));
+ }
+
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_eq_result<U> operator!=(const QVarLengthArray<T, Prealloc> &l, const QVarLengthArray<T, Prealloc2> &r)
+ {
+ return !(l == r);
+ }
+
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_lt_result<U> operator<(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
+ noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
+ rhs.begin(), rhs.end())))
+ {
+ return std::lexicographical_compare(lhs.begin(), lhs.end(),
+ rhs.begin(), rhs.end());
+ }
+
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_lt_result<U> operator>(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
+ noexcept(noexcept(lhs < rhs))
+ {
+ return rhs < lhs;
+ }
+
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_lt_result<U> operator<=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
+ noexcept(noexcept(lhs < rhs))
+ {
+ return !(lhs > rhs);
+ }
+
+ template <typename U = T, qsizetype Prealloc2 = Prealloc> friend
+ QTypeTraits::compare_lt_result<U> operator>=(const QVarLengthArray<T, Prealloc> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
+ noexcept(noexcept(lhs < rhs))
+ {
+ return !(lhs < rhs);
+ }
+#endif
+
private:
void reallocate(qsizetype size, qsizetype alloc);
@@ -626,52 +688,27 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
return ptr + f;
}
+#ifdef Q_QDOC
+// Fake definitions for qdoc, only the redeclaration is used.
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_eq_result<T> operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
-{
- if (l.size() != r.size())
- return false;
- const T *rb = r.begin();
- const T *b = l.begin();
- const T *e = l.end();
- return std::equal(b, e, QT_MAKE_CHECKED_ARRAY_ITERATOR(rb, r.size()));
-}
-
+bool operator==(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_eq_result<T> operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
-{
- return !(l == r);
-}
-
+bool operator!=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_lt_result<T> operator<(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
- noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),
- rhs.begin(), rhs.end())))
-{
- return std::lexicographical_compare(lhs.begin(), lhs.end(),
- rhs.begin(), rhs.end());
-}
-
+bool operator< (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_lt_result<T> operator>(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
- noexcept(noexcept(lhs < rhs))
-{
- return rhs < lhs;
-}
-
+bool operator> (const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_lt_result<T> operator<=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
- noexcept(noexcept(lhs < rhs))
-{
- return !(lhs > rhs);
-}
-
+bool operator<=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
template <typename T, qsizetype Prealloc1, qsizetype Prealloc2>
-QTypeTraits::compare_lt_result<T> operator>=(const QVarLengthArray<T, Prealloc1> &lhs, const QVarLengthArray<T, Prealloc2> &rhs)
- noexcept(noexcept(lhs < rhs))
-{
- return !(lhs < rhs);
-}
+bool operator>=(const QVarLengthArray<T, Prealloc1> &l, const QVarLengthArray<T, Prealloc2> &r)
+{ return bool{}; }
+#endif
template <typename T, qsizetype Prealloc>
size_t qHash(const QVarLengthArray<T, Prealloc> &key, size_t seed = 0)