diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-02-27 16:40:34 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-03-03 08:27:21 +0100 |
commit | bbe71efc23334ae928b887555d9cdee30fa826e3 (patch) | |
tree | c62ec96ba133665a5a2f477ad38f8e60a525d2be /src | |
parent | 5ebb03c47604e0597502fbe1069de636987f33fc (diff) |
Only declare comparison operators for QVector when comparable
This avoid SFINAE from incorrectly assuming QVectors of
non-comparable types has them.
Change-Id: Ie44eb7873384a0f41a6b8160c340b71ea25839dd
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qvector.h | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 026f99fd09..f8269bfe8c 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -738,31 +738,35 @@ uint qHash(const QVector<T> &key, uint seed = 0) } template <typename T> -bool operator<(const QVector<T> &lhs, const QVector<T> &rhs) +auto operator<(const QVector<T> &lhs, const QVector<T> &rhs) noexcept(noexcept(std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()))) + rhs.begin(), rhs.end()))) + -> decltype(std::declval<T>() < std::declval<T>()) { return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } template <typename T> -inline bool operator>(const QVector<T> &lhs, const QVector<T> &rhs) +auto operator>(const QVector<T> &lhs, const QVector<T> &rhs) noexcept(noexcept(lhs < rhs)) + -> decltype(lhs < rhs) { return rhs < lhs; } template <typename T> -inline bool operator<=(const QVector<T> &lhs, const QVector<T> &rhs) +auto operator<=(const QVector<T> &lhs, const QVector<T> &rhs) noexcept(noexcept(lhs < rhs)) + -> decltype(lhs < rhs) { return !(lhs > rhs); } template <typename T> -inline bool operator>=(const QVector<T> &lhs, const QVector<T> &rhs) +auto operator>=(const QVector<T> &lhs, const QVector<T> &rhs) noexcept(noexcept(lhs < rhs)) + -> decltype(lhs < rhs) { return !(lhs < rhs); } |