aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-24 12:07:55 +0100
committerAdrian Kummerlaender2015-01-24 12:07:55 +0100
commitf9844b741feac35622b9566c6afae9bb686f5149 (patch)
tree15c5791acb5506a19a9fb16cc785065a7e478a99
parent8432906bf9be6f16aafdb23aaed34f1247404329 (diff)
downloadTypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar.gz
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar.bz2
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar.lz
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar.xz
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.tar.zst
TypeAsValue-f9844b741feac35622b9566c6afae9bb686f5149.zip
Added `MakeList` list generator
* as its name implies this function returns a list of `Count` elements of value `Element` * added appropriate test case
-rw-r--r--src/list/generator/make_list.h30
-rw-r--r--test.cc31
2 files changed, 61 insertions, 0 deletions
diff --git a/src/list/generator/make_list.h b/src/list/generator/make_list.h
new file mode 100644
index 0000000..3bf65a2
--- /dev/null
+++ b/src/list/generator/make_list.h
@@ -0,0 +1,30 @@
+#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_
+#define TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_
+
+#include "list/cons.h"
+#include "operation/math.h"
+
+namespace tav {
+
+template <
+ typename Count,
+ typename Element
+>
+struct MakeList {
+ typedef Cons<
+ Element,
+ typename MakeList<
+ Substract<Count, Size<1>>,
+ Element
+ >::type
+ > type;
+};
+
+template <typename Element>
+struct MakeList<Size<1>, Element> {
+ typedef Cons<Element, void> type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_
diff --git a/test.cc b/test.cc
index 368cce5..1a20a74 100644
--- a/test.cc
+++ b/test.cc
@@ -11,6 +11,7 @@
#include "list/operation/higher/misc.h"
#include "list/operation/higher/query.h"
#include "list/generator/iota.h"
+#include "list/generator/make_list.h"
#include "list/generator/higher/list_tabulate.h"
int main(int, char **) { }
@@ -514,6 +515,18 @@ static_assert(
static_assert(
std::is_same<
+ tav::List<tav::Int<1>>::type,
+ tav::Iota<
+ tav::Size<1>,
+ tav::Int<1>,
+ tav::Int<1>
+ >::type
+ >::value,
+ "(iota 1 1 1) != (list 1)"
+);
+
+static_assert(
+ std::is_same<
tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type,
tav::Iota<
tav::Size<3>,
@@ -548,6 +561,24 @@ static_assert(
"(iota 5 5 -1) != (list 5 4 3 2 1)"
);
+// make list
+
+static_assert(
+ std::is_same<
+ tav::List<tav::Int<42>>::type,
+ tav::MakeList<tav::Size<1>, tav::Int<42>>::type
+ >::value,
+ "(make-list 1 42) != (list 42)"
+);
+
+static_assert(
+ std::is_same<
+ tav::List<tav::Int<42>, tav::Int<42>, tav::Int<42>>::type,
+ tav::MakeList<tav::Size<3>, tav::Int<42>>::type
+ >::value,
+ "(make-list 3 42) != (list 42 42 42)"
+);
+
// list tabulate
static_assert(