aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2019-12-27 15:10:36 +0100
committerFelix Morgner <felix.morgner@gmail.com>2019-12-27 15:10:36 +0100
commit03bed6e0dc6959fc06c4cba24b07d7b985b9237c (patch)
tree40da8a8bd911e93c5594c3cf64e77bbe86733806
parent99a77dd3122282f9509e7a4ec8bfd5b14b73e929 (diff)
downloadnewtype-03bed6e0dc6959fc06c4cba24b07d7b985b9237c.tar.xz
newtype-03bed6e0dc6959fc06c4cba24b07d7b985b9237c.zip
new_type: implement equality operators
-rw-r--r--include/newtype/new_type.hpp24
1 files 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<typename NewType = new_type, std::enable_if_t<NewType::derivations(nt::ImplicitConversion)> * = 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<typename NewType = new_type, std::enable_if_t<!NewType::derivations(nt::ImplicitConversion)> * = nullptr>
@@ -129,6 +129,26 @@ namespace nt
}
};
+ /**
+ * Compare two objects for equality
+ */
+ template<typename BaseType, typename TagType, auto DerivationClause>
+ auto constexpr operator==(new_type<BaseType, TagType, DerivationClause> const & lhs,
+ new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(lhs.decay() == rhs.decay())) -> bool
+ {
+ return lhs.decay() == rhs.decay();
+ }
+
+ /**
+ * Compare two objects for non-equality
+ */
+ template<typename BaseType, typename TagType, auto DerivationClause>
+ auto constexpr operator!=(new_type<BaseType, TagType, DerivationClause> const & lhs,
+ new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(!(lhs == rhs))) -> bool
+ {
+ return !(lhs == rhs);
+ }
+
} // namespace nt
#endif