From 3cac56267edfbfd26e203ad674b9b8e74e44b14e Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 19 Jan 2015 17:09:39 +0100 Subject: Implemented `Filter` in terms of `Fold` * as its name implies this _function_ only returns elements which evaluate to _true_ when passed to a given _function_ ** this marks the moment where _TypeAsValue_ supports something _ConstList_ does not, i.e. primary goal is achieved *** namely returning different types depending on the actual _values_ of a _Cons_ structure * added appropriate test case --- test.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test.cc') diff --git a/test.cc b/test.cc index 655aed3..35126fb 100644 --- a/test.cc +++ b/test.cc @@ -14,6 +14,9 @@ class TypeAsValueTest : public ::testing::Test { }; template using quadruple = tav::Multiply, Element>; +template +using odd = tav::Boolean<(Element::value % 2 == 1)>; + TEST_F(TypeAsValueTest, BasicMath) { // (+ 1 2) EXPECT_EQ(3, ( tav::Add, tav::Int<2>>::value )); @@ -99,6 +102,11 @@ TEST_F(TypeAsValueTest, ListMap) { EXPECT_TRUE(( std::is_same, tav::Int<8>, tav::Int<12>>::type, tav::Map, tav::Int<2>, tav::Int<3>>::type>::type>::value )); } +TEST_F(TypeAsValueTest, ListFilter) { + // (filter odd (list 1 2 3)) + EXPECT_TRUE(( std::is_same, tav::Int<3>>::type, tav::Filter, tav::Int<2>, tav::Int<3>>::type>::type>::value )); +} + TEST_F(TypeAsValueTest, ListReverse) { // (reverse (list 1 2 3)) EXPECT_TRUE(( std::is_same, tav::Int<2>, tav::Int<1>>::type, tav::Reverse, tav::Int<2>, tav::Int<3>>::type>::type>::value )); -- cgit v1.2.3