mirror of https://github.com/qt/qtbase.git
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 9f13842fe6
.
Task-number: QTBUG-120305
Pick-to: 6.8 6.5
Change-Id: Iaee96385a33ff131bdceabe945265b3285a370c2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
65fede8fae
commit
58c492a4dc
|
@ -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> {};
|
||||
|
|
Loading…
Reference in New Issue