From 8f7c10f3061fbfe5dbd80b9209f5b147837edeb8 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 28 Oct 2014 19:52:46 +0000 Subject: [PATCH] refs #345 Symmetric equality operators complete the original implementation of CValueObjectStdTuple. --- src/blackmisc/statusmessage.cpp | 17 ----------------- src/blackmisc/statusmessage.h | 6 ------ src/blackmisc/valueobject.h | 17 +++++++++++++++++ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/blackmisc/statusmessage.cpp b/src/blackmisc/statusmessage.cpp index 66f2c9bdd..f5d8bf940 100644 --- a/src/blackmisc/statusmessage.cpp +++ b/src/blackmisc/statusmessage.cpp @@ -60,23 +60,6 @@ namespace BlackMisc } } - /* - * Equal? - */ - bool CStatusMessage::operator ==(const CStatusMessage &other) const - { - if (this == &other) return true; - return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); - } - - /* - * Unequal? - */ - bool CStatusMessage::operator !=(const CStatusMessage &other) const - { - return !((*this) == other); - } - /* * Conversion */ diff --git a/src/blackmisc/statusmessage.h b/src/blackmisc/statusmessage.h index 5d0b77b75..183cf5014 100644 --- a/src/blackmisc/statusmessage.h +++ b/src/blackmisc/statusmessage.h @@ -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; } diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index f05f753bf..9d7b48882 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -278,6 +278,15 @@ namespace BlackMisc */ template 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(this); } Derived *derived() { return static_cast(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::toMetaTuple(a) == TupleConverter::toMetaTuple(b); + } }; /*!