diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/newtype/derivable.hpp | 7 | ||||
| -rw-r--r-- | include/newtype/new_type.hpp | 64 |
2 files changed, 71 insertions, 0 deletions
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 @@ -50,6 +50,13 @@ namespace nt auto constexpr Read = derivable<struct read_tag>{}; /** + * A tag to enable derivation of the relational operators + * + * @since 1.0.0 + */ + auto constexpr Relational = derivable<struct relational_tag>{}; + + /** * A tag to enable derivation of the stream output operator * * @since 1.0.0 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<typename BaseType, typename TagType, auto DerivationClause, typename = std::enable_if_t<DerivationClause(nt::Relational)>> + auto constexpr operator<(new_type<BaseType, TagType, DerivationClause> const & lhs, + new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(std::declval<BaseType const &>() < + std::declval<BaseType const &>())) + -> 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<typename BaseType, typename TagType, auto DerivationClause, typename = std::enable_if_t<DerivationClause(nt::Relational)>> + auto constexpr operator>(new_type<BaseType, TagType, DerivationClause> const & lhs, + new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(std::declval<BaseType const &>() > + std::declval<BaseType const &>())) + -> 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<typename BaseType, typename TagType, auto DerivationClause, typename = std::enable_if_t<DerivationClause(nt::Relational)>> + auto constexpr operator<=(new_type<BaseType, TagType, DerivationClause> const & lhs, + new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(std::declval<BaseType const &>() <= + std::declval<BaseType const &>())) + -> 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<typename BaseType, typename TagType, auto DerivationClause, typename = std::enable_if_t<DerivationClause(nt::Relational)>> + auto constexpr operator>=(new_type<BaseType, TagType, DerivationClause> const & lhs, + new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(noexcept(std::declval<BaseType const &>() >= + std::declval<BaseType const &>())) + -> bool + { + return lhs.decay() >= rhs.decay(); + } + } // namespace nt #endif |
