aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-23 20:32:48 +0100
committerAdrian Kummerlaender2015-01-23 20:32:48 +0100
commit8432906bf9be6f16aafdb23aaed34f1247404329 (patch)
tree230acd5c97b668ce47d34a0ae1a445cf93c91af3
parent0cbc85dd74103ec5c7b2ac5802721ccf051d8454 (diff)
downloadTypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar.gz
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar.bz2
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar.lz
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar.xz
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.tar.zst
TypeAsValue-8432906bf9be6f16aafdb23aaed34f1247404329.zip
Implemented `ListTabulate` in terms of `Iota` and `Map`
* added `Square` function to math operations header to facilitate a simple test case * added appropriate test case
-rw-r--r--src/list/generator/higher/list_tabulate.h20
-rw-r--r--src/list/generator/iota.h (renamed from src/list/iota.h)6
-rw-r--r--src/operation/math.h3
-rw-r--r--test.cc16
4 files changed, 41 insertions, 4 deletions
diff --git a/src/list/generator/higher/list_tabulate.h b/src/list/generator/higher/list_tabulate.h
new file mode 100644
index 0000000..9eee599
--- /dev/null
+++ b/src/list/generator/higher/list_tabulate.h
@@ -0,0 +1,20 @@
+#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_
+#define TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_
+
+#include "list/generator/iota.h"
+#include "list/operation/higher/misc.h"
+
+namespace tav {
+
+template <
+ typename Count,
+ template<typename> class Initializer
+>
+using ListTabulate = Map<
+ Initializer,
+ typename Iota<Count, Size<0>, Size<1>>::type
+>;
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_GENERATOR_HIGHER_LIST_TABULATE_H_
diff --git a/src/list/iota.h b/src/list/generator/iota.h
index 9a8d22d..54f0f40 100644
--- a/src/list/iota.h
+++ b/src/list/generator/iota.h
@@ -1,5 +1,5 @@
-#ifndef TYPEASVALUE_SRC_LIST_IOTA_H_
-#define TYPEASVALUE_SRC_LIST_IOTA_H_
+#ifndef TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_
+#define TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_
#include "operation/math.h"
@@ -31,4 +31,4 @@ struct Iota<Size<1>, Initial, Step> {
}
-#endif // TYPEASVALUE_SRC_LIST_IOTA_H_
+#endif // TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_
diff --git a/src/operation/math.h b/src/operation/math.h
index b06eb35..0ede3f5 100644
--- a/src/operation/math.h
+++ b/src/operation/math.h
@@ -41,6 +41,9 @@ using Divide = typename std::integral_constant<
X::value / Y::value
>::type;
+template <typename Base>
+using Square = Multiply<Base, Base>;
+
template <typename X>
using Even = Boolean<(X::value % 2 == 0)>;
diff --git a/test.cc b/test.cc
index 173aa19..368cce5 100644
--- a/test.cc
+++ b/test.cc
@@ -5,12 +5,13 @@
#include "list/cons.h"
#include "list/list.h"
-#include "list/iota.h"
#include "list/operation/reverse.h"
#include "list/operation/contains.h"
#include "list/operation/higher/fold.h"
#include "list/operation/higher/misc.h"
#include "list/operation/higher/query.h"
+#include "list/generator/iota.h"
+#include "list/generator/higher/list_tabulate.h"
int main(int, char **) { }
@@ -546,3 +547,16 @@ static_assert(
>::value,
"(iota 5 5 -1) != (list 5 4 3 2 1)"
);
+
+// list tabulate
+
+static_assert(
+ std::is_same<
+ tav::List<tav::Size<0>, tav::Size<1>, tav::Size<4>, tav::Size<9>>::type,
+ tav::ListTabulate<
+ tav::Size<4>,
+ tav::Square
+ >::type
+ >::value,
+ "(list-tabulate 4 square) != (list 0 1 4 9)"
+);