summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-03-27 20:56:44 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-04-05 16:57:37 +0000
commitdfb00bd479ded5bc4e86424c9678412c5ff72282 (patch)
tree10957199cd8462893ae1da5ab0fb87561b7a16a3 /src/corelib/tools/qlist.h
parenta03c633e4f13f17a7876d74248205bde539f2785 (diff)
QList: add relational operators <,<=,>,>=
std::vector has them, too. [ChangeLog][QtCore][QList] Added relational operators <, <=, >, >= if the element type supports operator<. Change-Id: Id2bd905e92c0365ad9f439d49908045c8df309c3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 57e67d52d7..7d90f72876 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -1015,6 +1015,36 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co
Q_DECLARE_SEQUENTIAL_ITERATOR(List)
Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
+template <typename T>
+bool operator<(const QList<T> &lhs, const QList<T> &rhs)
+ Q_DECL_NOEXCEPT_EXPR(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 T>
+inline bool operator>(const QList<T> &lhs, const QList<T> &rhs)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs))
+{
+ return rhs < lhs;
+}
+
+template <typename T>
+inline bool operator<=(const QList<T> &lhs, const QList<T> &rhs)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs))
+{
+ return !(lhs > rhs);
+}
+
+template <typename T>
+inline bool operator>=(const QList<T> &lhs, const QList<T> &rhs)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(lhs < rhs))
+{
+ return !(lhs < rhs);
+}
+
QT_END_NAMESPACE
#include <QtCore/qbytearraylist.h>