From 2b22ef0132e041917b6d8a566b12e955fea163b7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 14:52:36 +0200 Subject: derivations: introduce nt::contains concept --- source/lib/include/newtype/derivation_clause.hpp | 3 +++ source/lib/include/newtype/newtype.hpp | 15 +++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/lib/include/newtype/derivation_clause.hpp b/source/lib/include/newtype/derivation_clause.hpp index 6de70e1..c4aa051 100644 --- a/source/lib/include/newtype/derivation_clause.hpp +++ b/source/lib/include/newtype/derivation_clause.hpp @@ -65,6 +65,9 @@ namespace nt } }; + template + concept contains = requires(DerivationClause clause) { requires clause(Feature); }; + } // namespace nt #endif \ No newline at end of file diff --git a/source/lib/include/newtype/newtype.hpp b/source/lib/include/newtype/newtype.hpp index 126c439..33863ac 100644 --- a/source/lib/include/newtype/newtype.hpp +++ b/source/lib/include/newtype/newtype.hpp @@ -259,16 +259,14 @@ namespace nt return lhs.decay() == rhs.decay(); } - template - requires(DerivationClause(nt::EqBase)) + template auto DerivationClause> auto constexpr operator==(new_type const & lhs, BaseType const & rhs) noexcept(nt::concepts::nothrow_equality_comparable) -> bool { return lhs.decay() == rhs; } - template - requires(DerivationClause(nt::EqBase)) + template auto DerivationClause> auto constexpr operator==(BaseType const & lhs, new_type const & rhs) noexcept(nt::concepts::nothrow_equality_comparable) -> bool @@ -284,16 +282,14 @@ namespace nt return lhs.decay() != rhs.decay(); } - template - requires(DerivationClause(nt::EqBase)) + template auto DerivationClause> auto constexpr operator!=(new_type const & lhs, BaseType const & rhs) noexcept(nt::concepts::nothrow_inequality_comparable) -> bool { return lhs.decay() != rhs; } - template - requires(DerivationClause(nt::EqBase)) + template auto DerivationClause> auto constexpr operator!=(BaseType const & lhs, new_type const & rhs) noexcept(nt::concepts::nothrow_inequality_comparable) -> bool @@ -533,8 +529,7 @@ namespace nt namespace std { - template - requires(nt::concepts::hashable && DerivationClause(nt::Hash)) + template auto DerivationClause> struct hash> { auto constexpr operator()(nt::new_type const & object) const -- cgit v1.2.3