From 03bed6e0dc6959fc06c4cba24b07d7b985b9237c Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 27 Dec 2019 15:10:36 +0100 Subject: new_type: implement equality operators --- include/newtype/new_type.hpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 0dc0ff6..68a22dd 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -107,7 +107,7 @@ namespace nt /** * Convert this instance into the equivalent base type value * - * @note This overload participates only in overload resolution if the derication clause of this @p new_type contains + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type contains * nt::ImplicitConversion */ template * = nullptr> @@ -119,7 +119,7 @@ namespace nt /** * Convert this instance into the equivalent base type value * - * @note This overload participates only in overload resolution if the derication clause of this @p new_type does not contain + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type does not contain * nt::ImplicitConversion */ template * = nullptr> @@ -129,6 +129,26 @@ namespace nt } }; + /** + * Compare two objects for equality + */ + template + auto constexpr operator==(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(lhs.decay() == rhs.decay())) -> bool + { + return lhs.decay() == rhs.decay(); + } + + /** + * Compare two objects for non-equality + */ + template + auto constexpr operator!=(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(!(lhs == rhs))) -> bool + { + return !(lhs == rhs); + } + } // namespace nt #endif -- cgit v1.2.3