QUuid: add missing relational operators

QUuid has ==, !=, <, and >. Add <= and =>, too.

Change-Id: I11a0b8028be766e2d48dc7664d935df4d327b3d3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-04-03 21:47:52 +02:00
parent 09c1bd2eb0
commit 1b109967c5
3 changed files with 50 additions and 3 deletions

View File

@ -846,6 +846,34 @@ bool QUuid::operator>(const QUuid &other) const Q_DECL_NOTHROW
return other < *this; return other < *this;
} }
/*!
\fn bool operator<=(const QUuid &lhs, const QUuid &rhs)
\relates QUuid
\since 5.5
Returns \c true if \a lhs has the same \l{Variant field}
{variant field} as \a rhs and is lexicographically
\e{not after} \a rhs. If \a rhs has a
different variant field, the return value is determined by
comparing the two \l{QUuid::Variant} {variants}.
\sa variant()
*/
/*!
\fn bool operator>=(const QUuid &lhs, const QUuid &rhs)
\relates QUuid
\since 5.5
Returns \c true if \a lhs has the same \l{Variant field}
{variant field} as \a rhs and is lexicographically
\e{not before} \a rhs. If \a rhs has a
different variant field, the return value is determined by
comparing the two \l{QUuid::Variant} {variants}.
\sa variant()
*/
/*! /*!
\fn QUuid QUuid::createUuid() \fn QUuid QUuid::createUuid()

View File

@ -214,6 +214,11 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QUuid &);
Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT uint qHash(const QUuid &uuid, uint seed = 0) Q_DECL_NOTHROW;
inline bool operator<=(const QUuid &lhs, const QUuid &rhs) Q_DECL_NOTHROW
{ return !(rhs < lhs); }
inline bool operator>=(const QUuid &lhs, const QUuid &rhs) Q_DECL_NOTHROW
{ return !(lhs < rhs); }
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QUUID_H #endif // QUUID_H

View File

@ -260,19 +260,33 @@ void tst_QUuid::generate()
void tst_QUuid::less() void tst_QUuid::less()
{ {
QVERIFY( !(uuidA < uuidB) ); QVERIFY( uuidB < uuidA);
QVERIFY( uuidB <= uuidA);
QVERIFY(!(uuidA < uuidB) );
QVERIFY(!(uuidA <= uuidB));
QUuid null_uuid; QUuid null_uuid;
QVERIFY(null_uuid < uuidA); // Null uuid is always less than a valid one QVERIFY(null_uuid < uuidA); // Null uuid is always less than a valid one
QVERIFY(null_uuid <= uuidA);
QVERIFY(null_uuid <= null_uuid);
QVERIFY(uuidA <= uuidA);
} }
void tst_QUuid::more() void tst_QUuid::more()
{ {
QVERIFY( uuidA > uuidB ); QVERIFY( uuidA > uuidB);
QVERIFY( uuidA >= uuidB);
QVERIFY(!(uuidB > uuidA));
QVERIFY(!(uuidB >= uuidA));
QUuid null_uuid; QUuid null_uuid;
QVERIFY( !(null_uuid > uuidA) ); // Null uuid is always less than a valid one QVERIFY(!(null_uuid > uuidA)); // Null uuid is always less than a valid one
QVERIFY(!(null_uuid >= uuidA));
QVERIFY(null_uuid >= null_uuid);
QVERIFY(uuidA >= uuidA);
} }