diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 14:52:36 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 14:52:36 +0200 |
| commit | 2b22ef0132e041917b6d8a566b12e955fea163b7 (patch) | |
| tree | 5ad47fbc76fc5404c3f03c390a2585934703ebb6 | |
| parent | 2b92a0db8c3f171b6f947b749fa3a3c14e309d62 (diff) | |
| download | newtype-2b22ef0132e041917b6d8a566b12e955fea163b7.tar.xz newtype-2b22ef0132e041917b6d8a566b12e955fea163b7.zip | |
derivations: introduce nt::contains concept
| -rw-r--r-- | source/lib/include/newtype/derivation_clause.hpp | 3 | ||||
| -rw-r--r-- | 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<typename DerivationClause, auto Feature> + 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<nt::concepts::equality_comparable BaseType, typename TagType, auto DerivationClause> - requires(DerivationClause(nt::EqBase)) + template<nt::concepts::equality_comparable BaseType, typename TagType, nt::contains<nt::EqBase> auto DerivationClause> auto constexpr operator==(new_type<BaseType, TagType, DerivationClause> const & lhs, BaseType const & rhs) noexcept(nt::concepts::nothrow_equality_comparable<BaseType>) -> bool { return lhs.decay() == rhs; } - template<nt::concepts::equality_comparable BaseType, typename TagType, auto DerivationClause> - requires(DerivationClause(nt::EqBase)) + template<nt::concepts::equality_comparable BaseType, typename TagType, nt::contains<nt::EqBase> auto DerivationClause> auto constexpr operator==(BaseType const & lhs, new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(nt::concepts::nothrow_equality_comparable<BaseType>) -> bool @@ -284,16 +282,14 @@ namespace nt return lhs.decay() != rhs.decay(); } - template<nt::concepts::inequality_comparable BaseType, typename TagType, auto DerivationClause> - requires(DerivationClause(nt::EqBase)) + template<nt::concepts::inequality_comparable BaseType, typename TagType, nt::contains<nt::EqBase> auto DerivationClause> auto constexpr operator!=(new_type<BaseType, TagType, DerivationClause> const & lhs, BaseType const & rhs) noexcept(nt::concepts::nothrow_inequality_comparable<BaseType>) -> bool { return lhs.decay() != rhs; } - template<nt::concepts::inequality_comparable BaseType, typename TagType, auto DerivationClause> - requires(DerivationClause(nt::EqBase)) + template<nt::concepts::inequality_comparable BaseType, typename TagType, nt::contains<nt::EqBase> auto DerivationClause> auto constexpr operator!=(BaseType const & lhs, new_type<BaseType, TagType, DerivationClause> const & rhs) noexcept(nt::concepts::nothrow_inequality_comparable<BaseType>) -> bool @@ -533,8 +529,7 @@ namespace nt namespace std { - template<typename BaseType, typename TagType, auto DerivationClause> - requires(nt::concepts::hashable<BaseType> && DerivationClause(nt::Hash)) + template<nt::concepts::hashable BaseType, typename TagType, nt::contains<nt::Hash> auto DerivationClause> struct hash<nt::new_type<BaseType, TagType, DerivationClause>> { auto constexpr operator()(nt::new_type<BaseType, TagType, DerivationClause> const & object) const |
