aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/examples/src/basic_usage_with_read.cpp2
-rw-r--r--source/examples/src/basic_usage_with_show.cpp2
-rw-r--r--source/lib/include/newtype/derivable.hpp30
-rw-r--r--source/lib/include/newtype/derivation_clause.hpp75
-rw-r--r--source/lib/include/newtype/deriving.hpp20
-rw-r--r--source/lib/include/newtype/newtype.hpp91
-rw-r--r--source/tests/src/arithmetic.cpp2
-rw-r--r--source/tests/src/constructors.cpp1
-rw-r--r--source/tests/src/conversion.cpp2
-rw-r--r--source/tests/src/derivation_clause.cpp3
-rw-r--r--source/tests/src/equality_comparison.cpp2
-rw-r--r--source/tests/src/hash.cpp2
-rw-r--r--source/tests/src/io_operators.cpp2
-rw-r--r--source/tests/src/iterable.cpp2
-rw-r--r--source/tests/src/relational_operators.cpp2
15 files changed, 90 insertions, 148 deletions
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 <newtype/derivable.hpp>
-#include <newtype/deriving.hpp>
#include <newtype/newtype.hpp>
#include <iostream>
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 <newtype/derivable.hpp>
-#include <newtype/deriving.hpp>
#include <newtype/newtype.hpp>
#include <iostream>
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<typename DerivableTag>
- struct derivable final
- {
- using tag_type = DerivableTag;
- };
-
- inline namespace derivables
- {
-
- auto constexpr Arithmetic = derivable<struct arithmetic_tag>{};
- auto constexpr EqBase = derivable<struct eq_base_tag>{};
- auto constexpr Hash = derivable<struct hash_tag>{};
- auto constexpr ImplicitConversion = derivable<struct implicit_conversion_tag>{};
- auto constexpr Indirection = derivable<struct indirection_tag>{};
- auto constexpr Iterable = derivable<struct iterable_tag>{};
- auto constexpr Read = derivable<struct read_tag>{};
- auto constexpr Relational = derivable<struct relational_tag>{};
- auto constexpr Show = derivable<struct show_tag>{};
-
- } // 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 <type_traits>
-
-namespace nt
-{
-
- template<typename... DerivableTags>
- struct derivation_clause
- {
- template<auto... Needles>
- using contains = std::disjunction<std::is_same<DerivableTags, typename decltype(Needles)::tag_type>...>;
-
- constexpr derivation_clause(derivable<DerivableTags>...) noexcept
- {
- }
-
- template<typename DerivableTag>
- auto constexpr operator()(derivable<DerivableTag>) const noexcept -> bool
- {
- return (std::is_same_v<DerivableTags, DerivableTag> || ...);
- }
-
- template<typename DerivableTag, typename... RemainingDerivableTags>
- auto constexpr operator()(derivable<DerivableTag>, derivable<RemainingDerivableTags>...) const noexcept -> bool
- {
- return (*this)(derivable<DerivableTag>{}) && (*this)(derivable<RemainingDerivableTags>{}...);
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator<(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable<DerivableTags>{}...);
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator>(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return other < *this;
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator==(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable<DerivableTags>{}...);
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator!=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return !(*this == other);
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator<=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return *this < other || *this == other;
- }
-
- template<typename... OtherDerivableTags>
- auto constexpr operator>=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
- {
- return *this > other || *this == other;
- }
- };
-
- template<typename DerivationClause, auto... Features>
- concept contains = requires(DerivationClause clause) { requires DerivationClause::template contains<Features...>::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 <type_traits>
-
-namespace nt
-{
-
- template<typename... DerivableTags>
- auto constexpr deriving(derivable<DerivableTags>... features) noexcept -> derivation_clause<DerivableTags...>
- {
- 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<typename DerivableTag>
+ struct derivable final
+ {
+ using tag_type = DerivableTag;
+ };
+
+ inline namespace derivables
+ {
+
+ auto constexpr Arithmetic = derivable<struct arithmetic_tag>{};
+ auto constexpr EqBase = derivable<struct eq_base_tag>{};
+ auto constexpr Hash = derivable<struct hash_tag>{};
+ auto constexpr ImplicitConversion = derivable<struct implicit_conversion_tag>{};
+ auto constexpr Indirection = derivable<struct indirection_tag>{};
+ auto constexpr Iterable = derivable<struct iterable_tag>{};
+ auto constexpr Read = derivable<struct read_tag>{};
+ auto constexpr Relational = derivable<struct relational_tag>{};
+ auto constexpr Show = derivable<struct show_tag>{};
+
+ } // namespace derivables
+
+ template<typename... DerivableTags>
+ struct derivation_clause
+ {
+ template<auto... Needles>
+ using contains = std::disjunction<std::is_same<DerivableTags, typename decltype(Needles)::tag_type>...>;
+
+ constexpr derivation_clause(derivable<DerivableTags>...) noexcept
+ {
+ }
+
+ template<typename DerivableTag>
+ auto constexpr operator()(derivable<DerivableTag>) const noexcept -> bool
+ {
+ return (std::is_same_v<DerivableTags, DerivableTag> || ...);
+ }
+
+ template<typename DerivableTag, typename... RemainingDerivableTags>
+ auto constexpr operator()(derivable<DerivableTag>, derivable<RemainingDerivableTags>...) const noexcept -> bool
+ {
+ return (*this)(derivable<DerivableTag>{}) && (*this)(derivable<RemainingDerivableTags>{}...);
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator<(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable<DerivableTags>{}...);
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator>(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return other < *this;
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator==(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable<DerivableTags>{}...);
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator!=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return !(*this == other);
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator<=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return *this < other || *this == other;
+ }
+
+ template<typename... OtherDerivableTags>
+ auto constexpr operator>=(derivation_clause<OtherDerivableTags...> other) const noexcept -> bool
+ {
+ return *this > other || *this == other;
+ }
+ };
+
+ template<typename DerivationClause, auto... Features>
+ concept contains = requires(DerivationClause clause) { requires DerivationClause::template contains<Features...>::value; };
+
+ template<typename... DerivableTags>
+ auto constexpr deriving(derivable<DerivableTags>... features) noexcept -> derivation_clause<DerivableTags...>
+ {
+ return {features...};
+ }
+
template<typename BaseType, typename TagType, auto DerivationClause = deriving()>
class new_type
: impl::new_type_move_assignment<BaseType, TagType>
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 <catch2/catch_test_macros.hpp>
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 <catch2/catch_template_test_macros.hpp>
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 <catch2/catch_template_test_macros.hpp>
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 <catch2/catch_test_macros.hpp>
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 <catch2/catch_test_macros.hpp>
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 <catch2/catch_template_test_macros.hpp>
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 <catch2/catch_test_macros.hpp>
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 <catch2/catch_test_macros.hpp>
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 <catch2/catch_test_macros.hpp>