refs #345 Symmetric equality operators complete the original implementation of CValueObjectStdTuple.

This commit is contained in:
Mathew Sutcliffe
2014-10-28 19:52:46 +00:00
parent 1a5856e34c
commit 8f7c10f306
3 changed files with 17 additions and 23 deletions

View File

@@ -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
*/

View File

@@ -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; }

View File

@@ -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);
}
};
/*!