mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
refs #345 Symmetric equality operators complete the original implementation of CValueObjectStdTuple.
This commit is contained in:
@@ -60,23 +60,6 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
bool CStatusMessage::operator ==(const CStatusMessage &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return TupleConverter<CStatusMessage>::toTuple(*this) == TupleConverter<CStatusMessage>::toTuple(other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unequal?
|
||||
*/
|
||||
bool CStatusMessage::operator !=(const CStatusMessage &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Conversion
|
||||
*/
|
||||
|
||||
@@ -66,12 +66,6 @@ namespace BlackMisc
|
||||
//! \sa QtMessageHandler
|
||||
void toQtLogTriple(QtMsgType *o_type, QString *o_category, QString *o_message) const;
|
||||
|
||||
//! Equal operator ==
|
||||
bool operator ==(const CStatusMessage &other) const;
|
||||
|
||||
//! Unequal operator !=
|
||||
bool operator !=(const CStatusMessage &other) const;
|
||||
|
||||
//! Message category
|
||||
const CLogCategoryList &getCategories() const { return this->m_categories; }
|
||||
|
||||
|
||||
@@ -278,6 +278,15 @@ namespace BlackMisc
|
||||
*/
|
||||
template <class Derived> class CValueObjectStdTuple : public CValueObject
|
||||
{
|
||||
friend bool operator ==(const Derived &a, const Derived &b)
|
||||
{
|
||||
return equals(a, b);
|
||||
}
|
||||
|
||||
friend bool operator !=(const Derived &a, const Derived &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public:
|
||||
//! \copydoc CValueObject::getValueHash()
|
||||
@@ -362,6 +371,14 @@ namespace BlackMisc
|
||||
private:
|
||||
const Derived *derived() const { return static_cast<const Derived *>(this); }
|
||||
Derived *derived() { return static_cast<Derived *>(this); }
|
||||
|
||||
// Friend functions are implemented in terms of private static member functions, because
|
||||
// friendship is not transitive: friends of CValueObjectStdTuple are not friends of TupleConverter.
|
||||
static bool equals(const Derived &a, const Derived &b)
|
||||
{
|
||||
if (&a == &b) { return true; }
|
||||
return TupleConverter<Derived>::toMetaTuple(a) == TupleConverter<Derived>::toMetaTuple(b);
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user