aboutsummaryrefslogtreecommitdiff
path: root/src/list
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-16 22:08:09 +0100
committerAdrian Kummerlaender2015-01-16 22:08:09 +0100
commit01029e59e8eda0a160291c3c92f9db5b1cac54d3 (patch)
tree68aa6f35c44b7aa6b3e69e4c72047515826a02e2 /src/list
parent5ead1bfab50ef7b3f746f298c53788c833f03ce4 (diff)
downloadTypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar.gz
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar.bz2
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar.lz
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar.xz
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.tar.zst
TypeAsValue-01029e59e8eda0a160291c3c92f9db5b1cac54d3.zip
Implemented basic `Cons` value type and `List` constructor
* `Cons` is a straigth forward type _pair_ containing `car` and `cdr` typedefs ** they may be accessed using `Car` and `Cdr` helper template aliases ** there is no enforcement of _Cons_ structure and type equality whatsoever *** i.e. similar to Scheme and different from how it is implemented in _ConstList_ * `List` is a recursive variadic helper template for constructing `Cons` value types ** simplifies _Cons_ construction and may be expanded to offer type deduction and built upon to enforce type equality * added appropriate test cases
Diffstat (limited to 'src/list')
-rw-r--r--src/list/cons.h23
-rw-r--r--src/list/list.h26
2 files changed, 49 insertions, 0 deletions
diff --git a/src/list/cons.h b/src/list/cons.h
new file mode 100644
index 0000000..b858c4c
--- /dev/null
+++ b/src/list/cons.h
@@ -0,0 +1,23 @@
+#ifndef TYPEASVALUE_SRC_LIST_CONS_H_
+#define TYPEASVALUE_SRC_LIST_CONS_H_
+
+namespace tav {
+
+template <
+ typename CAR,
+ typename CDR
+>
+struct Cons {
+ typedef CAR car;
+ typedef CDR cdr;
+};
+
+template <typename Cons>
+using Car = typename Cons::car;
+
+template <typename Cons>
+using Cdr = typename Cons::cdr;
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_CONS_H_
diff --git a/src/list/list.h b/src/list/list.h
new file mode 100644
index 0000000..47d0d2f
--- /dev/null
+++ b/src/list/list.h
@@ -0,0 +1,26 @@
+#ifndef TYPEASVALUE_SRC_LIST_LIST_H_
+#define TYPEASVALUE_SRC_LIST_LIST_H_
+
+#include "cons.h"
+
+namespace tav {
+
+template <
+ typename Head,
+ typename... Tail
+>
+struct List {
+ typedef Cons<
+ Head,
+ typename List<Tail...>::type
+ > type;
+};
+
+template <typename Head>
+struct List<Head> {
+ typedef Cons<Head, void> type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_LIST_H_