From ea48c9f6545e2c12b64a03212130af9bf4c41e86 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 9 Jun 2023 13:56:34 +0200 Subject: newtype: merge derivable header to main header --- source/examples/src/basic_usage_with_read.cpp | 2 - source/examples/src/basic_usage_with_show.cpp | 2 - source/lib/include/newtype/derivable.hpp | 30 -------- source/lib/include/newtype/derivation_clause.hpp | 75 ------------------- source/lib/include/newtype/deriving.hpp | 20 ------ source/lib/include/newtype/newtype.hpp | 91 +++++++++++++++++++++++- source/tests/src/arithmetic.cpp | 2 - source/tests/src/constructors.cpp | 1 - source/tests/src/conversion.cpp | 2 - source/tests/src/derivation_clause.cpp | 3 +- source/tests/src/equality_comparison.cpp | 2 - source/tests/src/hash.cpp | 2 - source/tests/src/io_operators.cpp | 2 - source/tests/src/iterable.cpp | 2 - source/tests/src/relational_operators.cpp | 2 - 15 files changed, 90 insertions(+), 148 deletions(-) delete mode 100644 source/lib/include/newtype/derivable.hpp delete mode 100644 source/lib/include/newtype/derivation_clause.hpp delete mode 100644 source/lib/include/newtype/deriving.hpp diff --git a/source/examples/src/basic_usage_with_read.cpp b/source/examples/src/basic_usage_with_read.cpp index 2dabe2e..531a8e3 100644 --- a/source/examples/src/basic_usage_with_read.cpp +++ b/source/examples/src/basic_usage_with_read.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include diff --git a/source/examples/src/basic_usage_with_show.cpp b/source/examples/src/basic_usage_with_show.cpp index 4bb68f6..9e4d985 100644 --- a/source/examples/src/basic_usage_with_show.cpp +++ b/source/examples/src/basic_usage_with_show.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include diff --git a/source/lib/include/newtype/derivable.hpp b/source/lib/include/newtype/derivable.hpp deleted file mode 100644 index d4bd559..0000000 --- a/source/lib/include/newtype/derivable.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef NEWTYPE_DERIVABLE_HPP -#define NEWTYPE_DERIVABLE_HPP - -namespace nt -{ - - template - struct derivable final - { - using tag_type = DerivableTag; - }; - - inline namespace derivables - { - - auto constexpr Arithmetic = derivable{}; - auto constexpr EqBase = derivable{}; - auto constexpr Hash = derivable{}; - auto constexpr ImplicitConversion = derivable{}; - auto constexpr Indirection = derivable{}; - auto constexpr Iterable = derivable{}; - auto constexpr Read = derivable{}; - auto constexpr Relational = derivable{}; - auto constexpr Show = derivable{}; - - } // namespace derivables - -} // namespace nt - -#endif \ No newline at end of file diff --git a/source/lib/include/newtype/derivation_clause.hpp b/source/lib/include/newtype/derivation_clause.hpp deleted file mode 100644 index 1b9f48e..0000000 --- a/source/lib/include/newtype/derivation_clause.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef NEWTYPE_DERIVATION_CLAUSE_HPP -#define NEWTYPE_DERIVATION_CLAUSE_HPP - -#include "newtype/derivable.hpp" - -#include - -namespace nt -{ - - template - struct derivation_clause - { - template - using contains = std::disjunction...>; - - constexpr derivation_clause(derivable...) noexcept - { - } - - template - auto constexpr operator()(derivable) const noexcept -> bool - { - return (std::is_same_v || ...); - } - - template - auto constexpr operator()(derivable, derivable...) const noexcept -> bool - { - return (*this)(derivable{}) && (*this)(derivable{}...); - } - - template - auto constexpr operator<(derivation_clause other) const noexcept -> bool - { - return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable{}...); - } - - template - auto constexpr operator>(derivation_clause other) const noexcept -> bool - { - return other < *this; - } - - template - auto constexpr operator==(derivation_clause other) const noexcept -> bool - { - return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable{}...); - } - - template - auto constexpr operator!=(derivation_clause other) const noexcept -> bool - { - return !(*this == other); - } - - template - auto constexpr operator<=(derivation_clause other) const noexcept -> bool - { - return *this < other || *this == other; - } - - template - auto constexpr operator>=(derivation_clause other) const noexcept -> bool - { - return *this > other || *this == other; - } - }; - - template - concept contains = requires(DerivationClause clause) { requires DerivationClause::template contains::value; }; - -} // namespace nt - -#endif \ No newline at end of file diff --git a/source/lib/include/newtype/deriving.hpp b/source/lib/include/newtype/deriving.hpp deleted file mode 100644 index cbb1885..0000000 --- a/source/lib/include/newtype/deriving.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef NEWTYPE_DERIVING_HPP -#define NEWTYPE_DERIVING_HPP - -#include "newtype/derivable.hpp" -#include "newtype/derivation_clause.hpp" - -#include - -namespace nt -{ - - template - auto constexpr deriving(derivable... features) noexcept -> derivation_clause - { - return {features...}; - } - -} // 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 d5c4493..55ca19c 100644 --- a/source/lib/include/newtype/newtype.hpp +++ b/source/lib/include/newtype/newtype.hpp @@ -1,8 +1,6 @@ #ifndef NEWTYPE_NEWTYPE_HPP #define NEWTYPE_NEWTYPE_HPP -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/impl/new_type_iterator_types.hpp" #include "newtype/impl/new_type_storage.hpp" @@ -539,6 +537,95 @@ namespace nt } // namespace concepts + template + struct derivable final + { + using tag_type = DerivableTag; + }; + + inline namespace derivables + { + + auto constexpr Arithmetic = derivable{}; + auto constexpr EqBase = derivable{}; + auto constexpr Hash = derivable{}; + auto constexpr ImplicitConversion = derivable{}; + auto constexpr Indirection = derivable{}; + auto constexpr Iterable = derivable{}; + auto constexpr Read = derivable{}; + auto constexpr Relational = derivable{}; + auto constexpr Show = derivable{}; + + } // namespace derivables + + template + struct derivation_clause + { + template + using contains = std::disjunction...>; + + constexpr derivation_clause(derivable...) noexcept + { + } + + template + auto constexpr operator()(derivable) const noexcept -> bool + { + return (std::is_same_v || ...); + } + + template + auto constexpr operator()(derivable, derivable...) const noexcept -> bool + { + return (*this)(derivable{}) && (*this)(derivable{}...); + } + + template + auto constexpr operator<(derivation_clause other) const noexcept -> bool + { + return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable{}...); + } + + template + auto constexpr operator>(derivation_clause other) const noexcept -> bool + { + return other < *this; + } + + template + auto constexpr operator==(derivation_clause other) const noexcept -> bool + { + return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable{}...); + } + + template + auto constexpr operator!=(derivation_clause other) const noexcept -> bool + { + return !(*this == other); + } + + template + auto constexpr operator<=(derivation_clause other) const noexcept -> bool + { + return *this < other || *this == other; + } + + template + auto constexpr operator>=(derivation_clause other) const noexcept -> bool + { + return *this > other || *this == other; + } + }; + + template + concept contains = requires(DerivationClause clause) { requires DerivationClause::template contains::value; }; + + template + auto constexpr deriving(derivable... features) noexcept -> derivation_clause + { + return {features...}; + } + template class new_type : impl::new_type_move_assignment diff --git a/source/tests/src/arithmetic.cpp b/source/tests/src/arithmetic.cpp index 8161f0c..30c243f 100644 --- a/source/tests/src/arithmetic.cpp +++ b/source/tests/src/arithmetic.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/constructors.cpp b/source/tests/src/constructors.cpp index 75e1839..b866f2e 100644 --- a/source/tests/src/constructors.cpp +++ b/source/tests/src/constructors.cpp @@ -1,4 +1,3 @@ -#include "newtype/derivable.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/conversion.cpp b/source/tests/src/conversion.cpp index bcda06d..e7ce51c 100644 --- a/source/tests/src/conversion.cpp +++ b/source/tests/src/conversion.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/derivation_clause.cpp b/source/tests/src/derivation_clause.cpp index ddf28e7..bf0ab83 100644 --- a/source/tests/src/derivation_clause.cpp +++ b/source/tests/src/derivation_clause.cpp @@ -1,5 +1,4 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" +#include "newtype/newtype.hpp" #include diff --git a/source/tests/src/equality_comparison.cpp b/source/tests/src/equality_comparison.cpp index f01c3f9..e0be7f9 100644 --- a/source/tests/src/equality_comparison.cpp +++ b/source/tests/src/equality_comparison.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/hash.cpp b/source/tests/src/hash.cpp index 4c848d2..94f252f 100644 --- a/source/tests/src/hash.cpp +++ b/source/tests/src/hash.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/io_operators.cpp b/source/tests/src/io_operators.cpp index 2be41eb..f7f8f29 100644 --- a/source/tests/src/io_operators.cpp +++ b/source/tests/src/io_operators.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/iterable.cpp b/source/tests/src/iterable.cpp index bc862cc..85b7edc 100644 --- a/source/tests/src/iterable.cpp +++ b/source/tests/src/iterable.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include diff --git a/source/tests/src/relational_operators.cpp b/source/tests/src/relational_operators.cpp index de6f7f3..e852957 100644 --- a/source/tests/src/relational_operators.cpp +++ b/source/tests/src/relational_operators.cpp @@ -1,5 +1,3 @@ -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" #include "newtype/newtype.hpp" #include -- cgit v1.2.3