Skip to content

Commit

Permalink
GenericValue: refactoring of operator==/!=
Browse files Browse the repository at this point in the history
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=).
  • Loading branch information
pah committed Aug 20, 2014
1 parent 1adeecb commit 702b45b
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions include/rapidjson/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,28 +619,28 @@ class GenericValue {
}
}

//! Not-equal-to operator
bool operator!=(const GenericValue& rhs) const { return !(*this == 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 const C-string pointer
bool operator==(const Ch* rhs) const { return *this == GenericValue(StringRef(rhs)); }

//! 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 <typename T> friend bool operator==(const GenericValue& lhs, const T& rhs) { return lhs == GenericValue(rhs); }
template <typename T> friend bool operator!=(const GenericValue& lhs, const T& rhs) { return !(lhs == rhs); }
template <typename T> friend bool operator==(const T& lhs, const GenericValue& rhs) { return GenericValue(lhs) == rhs; }
template <typename T> friend bool operator!=(const T& lhs, const GenericValue& rhs) { return !(lhs == rhs); }
template <typename T> RAPIDJSON_DISABLEIF_RETURN(internal::IsPointer<T>, bool) operator==(const T& rhs) const { return *this == GenericValue(rhs); }

//! Not-equal-to operator with arbitrary types
/*! \return !(*this == rhs)
*/
template <typename T> bool operator!=(const T& rhs) const { return !(*this == rhs); }

//! Equal-to operator with arbitrary types (symmetric version)
/*! \return (rhs == lhs)
*/
template <typename T> 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 <typename T> friend bool operator!=(const T& lhs, const GenericValue& rhs) { return !(rhs == lhs); }
//@}

//!@name Type
Expand Down

0 comments on commit 702b45b

Please sign in to comment.