summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-08-03 16:42:30 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-08-04 20:04:54 +0200
commit31c232d3b7297cbc288815297c75968d5c80ac18 (patch)
treecf6963a1defd4f9bdedb7b7a2de0e217d00bf2ca
parent8003ae79bfd72736b809805afbb7984c3431031e (diff)
QList: properly declare operator== for MSVC
The operators were declared as friend function templates (so, free functions in the Qt namespace). Unfortunately, the template argument of the operators was also defaulted -- causing MSVC trying to instantiate those functions at all times, causing interesting recursive template instantiation errors (C2968). It's extremely likely that we're facing a MSVC bug, but work around it by not defaulting the template argument. This in turn requires to move the function definition outside QList's definition, otherwise an extern template definition (like the ones we have for QList<QPoint>) would cause a template redefinition error... Change-Id: If03477ac1fa0a72aa252bb9e08e2a19c2b517b1b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/tools/qlist.h38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 443789b411..35dc286191 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -162,22 +162,10 @@ public:
void swap(QList<T> &other) noexcept { qSwap(d, other.d); }
- template <typename U = T>
- friend QTypeTraits::compare_eq_result<U> operator==(const QList &l, const QList &r)
- {
- if (l.size() != r.size())
- return false;
- if (l.begin() == r.begin())
- return true;
-
- // do element-by-element comparison
- return l.d->compare(l.begin(), r.begin(), l.size());
- }
- template <typename U = T>
- friend QTypeTraits::compare_eq_result<U> operator!=(const QList &l, const QList &r)
- {
- return !(l == r);
- }
+ template <typename U>
+ friend QTypeTraits::compare_eq_result<U> operator==(const QList<U> &l, const QList<U> &r);
+ template <typename U>
+ friend QTypeTraits::compare_eq_result<U> operator!=(const QList<U> &l, const QList<U> &r);
qsizetype size() const noexcept { return d->size; }
qsizetype count() const noexcept { return size(); }
@@ -792,6 +780,24 @@ size_t qHash(const QList<T> &key, size_t seed = 0)
return qHashRange(key.cbegin(), key.cend(), seed);
}
+template <typename U>
+QTypeTraits::compare_eq_result<U> operator==(const QList<U> &l, const QList<U> &r)
+{
+ if (l.size() != r.size())
+ return false;
+ if (l.begin() == r.begin())
+ return true;
+
+ // do element-by-element comparison
+ return l.d->compare(l.begin(), r.begin(), l.size());
+}
+
+template <typename U>
+QTypeTraits::compare_eq_result<U> operator!=(const QList<U> &l, const QList<U> &r)
+{
+ return !(l == r);
+}
+
template <typename T>
auto operator<(const QList<T> &lhs, const QList<T> &rhs)
noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(),