aboutsummaryrefslogtreecommitdiff
path: root/src/list/cons.h
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-06 19:26:26 +0100
committerAdrian Kummerlaender2015-02-06 19:26:26 +0100
commit27aaee43499c268903332c7e9e1e6ec2d193dc3a (patch)
treefcd6a361aa5ce6a9c095f496886807f87af85ea0 /src/list/cons.h
parent1e0528b1a870e0e0f2b15f468fc60f80e5fc20b3 (diff)
downloadTypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar.gz
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar.bz2
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar.lz
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar.xz
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.tar.zst
TypeAsValue-27aaee43499c268903332c7e9e1e6ec2d193dc3a.zip
Revamped to use `Cons` as a function and `Pair` as its result
* this is analogous to _Scheme_ where a pair (dot-expression) is returned from a call to `cons` * `Head` and `Tail` are kept as direct references to the `CAR` and `CDR` values of a pair to match e.g. the math operators
Diffstat (limited to 'src/list/cons.h')
-rw-r--r--src/list/cons.h27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/list/cons.h b/src/list/cons.h
index b858c4c..7f54eb5 100644
--- a/src/list/cons.h
+++ b/src/list/cons.h
@@ -1,6 +1,8 @@
#ifndef TYPEASVALUE_SRC_LIST_CONS_H_
#define TYPEASVALUE_SRC_LIST_CONS_H_
+#include "pair.h"
+
namespace tav {
template <
@@ -8,15 +10,28 @@ template <
typename CDR
>
struct Cons {
- typedef CAR car;
- typedef CDR cdr;
+ typedef Pair<CAR, CDR> type;
};
-template <typename Cons>
-using Car = typename Cons::car;
+template <typename Pair>
+struct Car {
+ static_assert(
+ IsPair<Pair>::type::value,
+ "Pair type required"
+ );
+
+ typedef typename Pair::car type;
+};
-template <typename Cons>
-using Cdr = typename Cons::cdr;
+template <typename Pair>
+struct Cdr {
+ static_assert(
+ IsPair<Pair>::type::value,
+ "Pair type required"
+ );
+
+ typedef typename Pair::cdr type;
+};
}