aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-16 17:35:38 +0100
committerAdrian Kummerlaender2015-02-16 17:35:38 +0100
commitf81cd736e00c28cf24412a4099bae08ff2e6c493 (patch)
treedc8a8ed7efef0f495adf5573b1fa5a43f6d08333 /src
parent5a9366307d23b220657629c494827def3544c490 (diff)
downloadTypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar.gz
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar.bz2
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar.lz
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar.xz
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.tar.zst
TypeAsValue-f81cd736e00c28cf24412a4099bae08ff2e6c493.zip
Unified `Iota` and `MakeList` using nested structure generator
* `detail::generate_nested_structure` offers a higher order nested structure constructor for procedural list generation * renamed `Fold` implementation details
Diffstat (limited to 'src')
-rw-r--r--src/function/detail/apply.h11
-rw-r--r--src/list/generator/detail/generate_nested_structure.h39
-rw-r--r--src/list/generator/iota.h38
-rw-r--r--src/list/generator/make_list.h34
-rw-r--r--src/list/operation/higher/fold.h8
-rw-r--r--src/list/operation/nth.h3
6 files changed, 65 insertions, 68 deletions
diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h
index 3df80ef..aca0af4 100644
--- a/src/function/detail/apply.h
+++ b/src/function/detail/apply.h
@@ -13,17 +13,12 @@ namespace detail {
struct placeholder_tag { };
template <typename Type>
-using is_placeholder = Boolean<
- std::is_base_of<placeholder_tag, Type>::value
->;
+using is_placeholder = Eval<std::is_base_of<placeholder_tag, Type>>;
template <int Index>
struct placeholder : placeholder_tag { };
-template <
- typename Partials,
- typename Argument
->
+template <typename, typename Argument>
struct resolve_placeholder {
typedef Argument type;
};
@@ -33,7 +28,7 @@ template <
int Index
>
struct resolve_placeholder<Partials, placeholder<Index>> {
- typedef tav::Nth<Size<Index>, Partials> type;
+ typedef Nth<Size<Index>, Partials> type;
};
template <typename... Arguments>
diff --git a/src/list/generator/detail/generate_nested_structure.h b/src/list/generator/detail/generate_nested_structure.h
new file mode 100644
index 0000000..84db78d
--- /dev/null
+++ b/src/list/generator/detail/generate_nested_structure.h
@@ -0,0 +1,39 @@
+#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_DETAIL_GENERATE_NESTED_STRUCTURE_H_
+#define TYPEASVALUE_SRC_LIST_GENERATOR_DETAIL_GENERATE_NESTED_STRUCTURE_H_
+
+namespace tav {
+
+namespace detail {
+
+template <
+ template <typename, typename> class Structure,
+ template <typename> class Generator,
+ typename Initial,
+ typename Count
+>
+struct generate_nested_structure {
+ typedef Structure<
+ Initial,
+ Eval<generate_nested_structure<
+ Structure,
+ Generator,
+ Generator<Initial>,
+ Substract<Count, Size<1>>
+ >>
+ > type;
+};
+
+template <
+ template <typename, typename> class Structure,
+ template <typename> class Generator,
+ typename Initial
+>
+struct generate_nested_structure<Structure, Generator, Initial, Size<0>> {
+ typedef void type;
+};
+
+}
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_GENERATOR_DETAIL_GENERATE_NESTED_STRUCTURE_H_
diff --git a/src/list/generator/iota.h b/src/list/generator/iota.h
index 73b7cc8..1def67e 100644
--- a/src/list/generator/iota.h
+++ b/src/list/generator/iota.h
@@ -1,44 +1,24 @@
#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_
#define TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_
+#include "pair.h"
#include "operation/math.h"
+#include "function/apply.h"
+#include "detail/generate_nested_structure.h"
namespace tav {
-namespace detail {
-
-template <
- typename Count,
- typename Initial,
- typename Step
->
-struct Iota {
- typedef Cons<
- Initial,
- Eval<Iota<
- Substract<Count, Size<1>>,
- Add<Initial, Step>,
- Step
- >>
- > type;
-};
-
-template <
- typename Initial,
- typename Step
->
-struct Iota<Size<1>, Initial, Step> {
- typedef Cons<Initial, void> type;
-};
-
-}
-
template <
typename Count,
typename Initial,
typename Step
>
-using Iota = Eval<detail::Iota<Count, Initial, Step>>;
+using Iota = Eval<detail::generate_nested_structure<
+ Pair,
+ Apply<Add, Step, _0>::template function,
+ Initial,
+ Count
+>>;
}
diff --git a/src/list/generator/make_list.h b/src/list/generator/make_list.h
index 863dce2..ec49651 100644
--- a/src/list/generator/make_list.h
+++ b/src/list/generator/make_list.h
@@ -1,39 +1,21 @@
#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_
#define TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_
-#include "list/cons.h"
-#include "operation/math.h"
+#include "pair.h"
+#include "detail/generate_nested_structure.h"
namespace tav {
-namespace detail {
-
-template <
- typename Count,
- typename Element
->
-struct MakeList {
- typedef Cons<
- Element,
- Eval<MakeList<
- Substract<Count, Size<1>>,
- Element
- >>
- > type;
-};
-
-template <typename Element>
-struct MakeList<Size<1>, Element> {
- typedef Cons<Element, void> type;
-};
-
-}
-
template <
typename Count,
typename Element
>
-using MakeList = Eval<detail::MakeList<Count, Element>>;
+using MakeList = Eval<detail::generate_nested_structure<
+ Pair,
+ Eval,
+ Element,
+ Count
+>>;
}
diff --git a/src/list/operation/higher/fold.h b/src/list/operation/higher/fold.h
index 7364fe5..3f39b40 100644
--- a/src/list/operation/higher/fold.h
+++ b/src/list/operation/higher/fold.h
@@ -10,10 +10,10 @@ template <
typename Initial,
typename Current
>
-struct Fold {
+struct fold_pair {
typedef Function<
Head<Current>,
- Eval<Fold<Function, Initial, Tail<Current>>>
+ Eval<fold_pair<Function, Initial, Tail<Current>>>
> type;
};
@@ -21,7 +21,7 @@ template <
template<typename, typename> class Function,
typename Initial
>
-struct Fold<Function, Initial, void> {
+struct fold_pair<Function, Initial, void> {
typedef Initial type;
};
@@ -32,7 +32,7 @@ template <
typename Initial,
typename Current
>
-using Fold = Eval<detail::Fold<Function, Initial, Current>>;
+using Fold = Eval<detail::fold_pair<Function, Initial, Current>>;
}
diff --git a/src/list/operation/nth.h b/src/list/operation/nth.h
index 0a56ba3..1ffb1f0 100644
--- a/src/list/operation/nth.h
+++ b/src/list/operation/nth.h
@@ -1,8 +1,9 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
-#include "operation/math.h"
#include "drop.h"
+#include "conditional/if.h"
+#include "operation/math.h"
namespace tav {