aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-16 23:55:01 +0100
committerAdrian Kummerlaender2015-01-16 23:55:01 +0100
commitf922e0b5dfc0a03378b231ad2705dbef29310d56 (patch)
tree5eba4408c43405284d0b205a616265d12fdde15f
parent01029e59e8eda0a160291c3c92f9db5b1cac54d3 (diff)
downloadTypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar.gz
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar.bz2
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar.lz
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar.xz
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.tar.zst
TypeAsValue-f922e0b5dfc0a03378b231ad2705dbef29310d56.zip
Implemented recursive `Concatenate` _Cons_ constructor
* concatenates two given _Cons_ based lists into a single one
-rw-r--r--src/list/list.h25
-rw-r--r--test.cc13
2 files changed, 34 insertions, 4 deletions
diff --git a/src/list/list.h b/src/list/list.h
index 47d0d2f..edd46e8 100644
--- a/src/list/list.h
+++ b/src/list/list.h
@@ -21,6 +21,31 @@ struct List<Head> {
typedef Cons<Head, void> type;
};
+template <typename Cons>
+using Head = Car<Cons>;
+
+template <typename Cons>
+using Tail = Cdr<Cons>;
+
+template <
+ typename Primary,
+ typename Secondary
+>
+struct Concatenate {
+ typedef Cons<
+ Head<Primary>,
+ typename Concatenate<
+ Tail<Primary>,
+ Secondary
+ >::type
+ > type;
+};
+
+template <typename Secondary>
+struct Concatenate<void, Secondary> {
+ typedef Secondary type;
+};
+
}
#endif // TYPEASVALUE_SRC_LIST_LIST_H_
diff --git a/test.cc b/test.cc
index e2b7186..5b24c32 100644
--- a/test.cc
+++ b/test.cc
@@ -32,10 +32,15 @@ TEST_F(TypeAsValueTest, Cons) {
}
TEST_F(TypeAsValueTest, List) {
- EXPECT_EQ(1, ( tav::Car<tav::List<tav::Int<1>>::type>::value ));
- EXPECT_EQ(1, ( tav::Car<tav::List<tav::Int<1>, tav::Int<2>>::type>::value ));
- EXPECT_EQ(2, ( tav::Car<tav::Cdr<tav::List<tav::Int<1>, tav::Int<2>>::type>>::value ));
- EXPECT_EQ(2, ( tav::Car<tav::Cdr<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>>::value ));
+ EXPECT_EQ(1, ( tav::Head<tav::List<tav::Int<1>>::type>::value ));
+ EXPECT_EQ(1, ( tav::Head<tav::List<tav::Int<1>, tav::Int<2>>::type>::value ));
+ EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::List<tav::Int<1>, tav::Int<2>>::type>>::value ));
+ EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>>::value ));
+}
+
+TEST_F(TypeAsValueTest, ListConcatenate) {
+ EXPECT_EQ(1, ( tav::Head<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>::value ));
+ EXPECT_EQ(2, ( tav::Head<tav::Tail<tav::Concatenate<tav::List<tav::Int<1>>::type, tav::List<tav::Int<2>>::type>::type>>::value ));
}
int main(int argc, char **argv) {