tst_collections.cpp: fix RecursiveList comparison case

The RecursiveList structure was defined like this:

 struct RecursiveList : public QList<RecursiveList> {};

However, this definition does not make any sense when it comes to the
relational operators. QList<T> needs to have operator<() defined for
the contained type T.

The current implementation of QTypeTraits::compare_lt_result_container
simply enables operator<() if Container is a base type of the contained
type. This unblocks the compilation of checks like

 static_assert(QTypeTraits::has_operator_less_than_v<RecursiveList>);

However, this is useless in practice.

This commit updates the struct to have a meaningful definition of
operator<().

Amends 9f13842fe61541cb8ab9822174ea963e418b5537.

Task-number: QTBUG-120305
Pick-to: 6.5
Change-Id: Iaee96385a33ff131bdceabe945265b3285a370c2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 58c492a4dc9868faff7e9334758947cf0027eeac)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2024-12-03 13:33:51 +01:00 committed by Qt Cherry-pick Bot
parent 09ddc1b893
commit 528c78d3a2

View File

@ -155,7 +155,15 @@ struct Dummy
bool operator<(const Dummy &) const { return false; }
};
struct RecursiveList : public QList<RecursiveList> {};
struct RecursiveList : public QList<RecursiveList>
{
friend bool operator<(const RecursiveList &lhs, const RecursiveList &rhs)
{
using Base = QList<RecursiveList>;
// compare some non-QList members here
return static_cast<const Base &>(lhs) < static_cast<const Base &>(rhs);
}
};
struct RecursiveSet : public QSet<RecursiveSet> {};
struct RecursiveMapV : public QMap<Dummy, RecursiveMapV> {};
struct RecursiveMapK : public QMap<RecursiveMapK, Dummy> {};