diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2019-12-28 18:39:54 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2019-12-28 18:39:54 +0100 |
| commit | d8c5b02674d905f47f288b2fd20f88cb1f5fc792 (patch) | |
| tree | 0640ff974cabd31183ccf608c86d0f1aab34808f /include | |
| parent | 65f0b622e390edb39a6cfd8d614374314472a5a9 (diff) | |
| download | newtype-d8c5b02674d905f47f288b2fd20f88cb1f5fc792.tar.xz newtype-d8c5b02674d905f47f288b2fd20f88cb1f5fc792.zip | |
new_type: implement support for nt::Relational
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 |
