diff options
-rw-r--r-- | src/list/list.h | 25 | ||||
-rw-r--r-- | 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<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_ @@ -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) { |