From f922e0b5dfc0a03378b231ad2705dbef29310d56 Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender
Date: Fri, 16 Jan 2015 23:55:01 +0100
Subject: Implemented recursive `Concatenate` _Cons_ constructor * concatenates
two given _Cons_ based lists into a single one
---
src/list/list.h | 25 +++++++++++++++++++++++++
test.cc | 13 +++++++++----
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
{
typedef Cons type;
};
+template
+using Head = Car;
+
+template
+using Tail = Cdr;
+
+template <
+ typename Primary,
+ typename Secondary
+>
+struct Concatenate {
+ typedef Cons<
+ Head,
+ typename Concatenate<
+ Tail,
+ Secondary
+ >::type
+ > type;
+};
+
+template
+struct Concatenate {
+ 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>::type>::value ));
- EXPECT_EQ(1, ( tav::Car, tav::Int<2>>::type>::value ));
- EXPECT_EQ(2, ( tav::Car, tav::Int<2>>::type>>::value ));
- EXPECT_EQ(2, ( tav::Car, tav::Int<2>, tav::Int<3>>::type>>::value ));
+ EXPECT_EQ(1, ( tav::Head>::type>::value ));
+ EXPECT_EQ(1, ( tav::Head, tav::Int<2>>::type>::value ));
+ EXPECT_EQ(2, ( tav::Head, tav::Int<2>>::type>>::value ));
+ EXPECT_EQ(2, ( tav::Head, tav::Int<2>, tav::Int<3>>::type>>::value ));
+}
+
+TEST_F(TypeAsValueTest, ListConcatenate) {
+ EXPECT_EQ(1, ( tav::Head>::type, tav::List>::type>::type>::value ));
+ EXPECT_EQ(2, ( tav::Head>::type, tav::List>::type>::type>>::value ));
}
int main(int argc, char **argv) {
--
cgit v1.2.3