From d8c5b02674d905f47f288b2fd20f88cb1f5fc792 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 28 Dec 2019 18:39:54 +0100 Subject: new_type: implement support for nt::Relational --- include/newtype/derivable.hpp | 7 +++++ include/newtype/new_type.hpp | 64 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) (limited to 'include') diff --git a/include/newtype/derivable.hpp b/include/newtype/derivable.hpp index 4fec2b7..157bac7 100644 --- a/include/newtype/derivable.hpp +++ b/include/newtype/derivable.hpp @@ -49,6 +49,13 @@ namespace nt */ auto constexpr Read = derivable{}; + /** + * A tag to enable derivation of the relational operators + * + * @since 1.0.0 + */ + auto constexpr Relational = derivable{}; + /** * A tag to enable derivation of the stream output operator * diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index c0fb8d3..17959ba 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -153,6 +153,70 @@ namespace nt return lhs.decay() != rhs.decay(); } + /** + * Check if one nt::new_type object is less-than an other + * + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type does contain + * nt::Relational + * @return true iff. the object contained by lhs is less-than the one contained by rhs + */ + template> + auto constexpr operator<(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(std::declval() < + std::declval())) + -> bool + { + return lhs.decay() < rhs.decay(); + } + + /** + * Check if one nt::new_type object is greater-than an other + * + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type does contain + * nt::Relational + * @return true iff. the object contained by lhs is greater-than the one contained by rhs + */ + template> + auto constexpr operator>(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(std::declval() > + std::declval())) + -> bool + { + return lhs.decay() > rhs.decay(); + } + + /** + * Check if one nt::new_type object is less-than or equal-to an other + * + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type does contain + * nt::Relational + * @return true iff. the object contained by lhs is less-than or equal-to the one contained by rhs + */ + template> + auto constexpr operator<=(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(std::declval() <= + std::declval())) + -> bool + { + return lhs.decay() <= rhs.decay(); + } + + /** + * Check if one nt::new_type object is greater-than or equal-to an other + * + * @note This overload participates only in overload resolution if the derivation clause of this @p new_type does contain + * nt::Relational + * @return true iff. the object contained by lhs is greater-than or equal-to the one contained by rhs + */ + template> + auto constexpr operator>=(new_type const & lhs, + new_type const & rhs) noexcept(noexcept(std::declval() >= + std::declval())) + -> bool + { + return lhs.decay() >= rhs.decay(); + } + } // namespace nt #endif -- cgit v1.2.3