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>
This commit is contained in:
parent
8003ae79bf
commit
31c232d3b7
@ -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(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user