From 702b45bb6e3c84fa87c7cf3513b92c1a8c18f3c6 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Tue, 19 Aug 2014 16:03:16 +0200 Subject: [PATCH] GenericValue: refactoring of operator==/!= By restructuring the call forwarding of the various operator== and operator!= overloads, new overloads can be added by simply adding an additional member operator==. Additionally, the "Ch*" overloads are dropped in favour of an SFINAE version that removes the pointer variants from matching the templated operator== (see also operator=). --- include/rapidjson/document.h | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index a44c0ea..5322076 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -619,28 +619,28 @@ public: } } - //! Not-equal-to operator - bool operator!=(const GenericValue& rhs) const { return !(*this == rhs); } + //! Equal-to operator with const C-string pointer + bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); } - //! (Not-)Equal-to operator with const C-string pointer. - friend bool operator==(const GenericValue& lhs, const Ch* rhs) { return lhs == GenericValue(StringRef(rhs)); } - friend bool operator!=(const GenericValue& lhs, const Ch* rhs) { return !(lhs == rhs); } - friend bool operator==(const Ch* lhs, const GenericValue& rhs) { return GenericValue(StringRef(lhs)) == rhs; } - friend bool operator!=(const Ch* lhs, const GenericValue& rhs) { return !(lhs == rhs); } - - //! (Not-)Equal-to operator with non-const C-string pointer. - friend bool operator==(const GenericValue& lhs, Ch* rhs) { return lhs == GenericValue(StringRef(rhs)); } - friend bool operator!=(const GenericValue& lhs, Ch* rhs) { return !(lhs == rhs); } - friend bool operator==(Ch* lhs, const GenericValue& rhs) { return GenericValue(StringRef(lhs)) == rhs; } - friend bool operator!=(Ch* lhs, const GenericValue& rhs) { return !(lhs == rhs); } - - //! (Not-)Equal-to operator with primitive types. + //! Equal-to operator with primitive types /*! \tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c double, \c true, \c false */ - template friend bool operator==(const GenericValue& lhs, const T& rhs) { return lhs == GenericValue(rhs); } - template friend bool operator!=(const GenericValue& lhs, const T& rhs) { return !(lhs == rhs); } - template friend bool operator==(const T& lhs, const GenericValue& rhs) { return GenericValue(lhs) == rhs; } - template friend bool operator!=(const T& lhs, const GenericValue& rhs) { return !(lhs == rhs); } + template RAPIDJSON_DISABLEIF_RETURN(internal::IsPointer, bool) operator==(const T& rhs) const { return *this == GenericValue(rhs); } + + //! Not-equal-to operator with arbitrary types + /*! \return !(*this == rhs) + */ + template bool operator!=(const T& rhs) const { return !(*this == rhs); } + + //! Equal-to operator with arbitrary types (symmetric version) + /*! \return (rhs == lhs) + */ + template friend bool operator==(const T& lhs, const GenericValue& rhs) { return rhs == lhs; } + + //! Not-Equal-to operator with arbitrary types (symmetric version) + /*! \return !(rhs == lhs) + */ + template friend bool operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); } //@} //!@name Type