aboutsummaryrefslogtreecommitdiff
path: root/src/list/generator
diff options
context:
space:
mode:
Diffstat (limited to 'src/list/generator')
-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
3 files changed, 56 insertions, 55 deletions
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
+>>;
}