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 --- src/list/operation/basic.h | 4 ++-- src/list/operation/higher/misc.h | 32 ++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src/list') diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index 364a542..d80b347 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -13,12 +13,12 @@ class Length { typename, typename Previous > - struct Count { + struct count { typedef Add, Previous> type; }; public: - typedef typename Fold, Cons>::type type; + typedef typename Fold, Cons>::type type; }; diff --git a/src/list/operation/higher/misc.h b/src/list/operation/higher/misc.h index 280c0d5..95a5f50 100644 --- a/src/list/operation/higher/misc.h +++ b/src/list/operation/higher/misc.h @@ -3,6 +3,7 @@ #include "fold.h" #include "list/operation/concatenate.h" +#include "conditional/if.h" namespace tav { @@ -16,12 +17,35 @@ class Map { typename Current, typename Previous > - struct FunctionWrapper { + struct function_wrapper { typedef Cons, Previous> type; }; public: - typedef typename Fold::type type; + typedef typename Fold::type type; + +}; + +template < + template class Function, + typename List +> +class Filter { + private: + template < + typename Current, + typename Previous + > + struct function_wrapper { + typedef If< + Function::type::value, + Cons, + Previous + > type; + }; + + public: + typedef typename Fold::type type; }; @@ -32,7 +56,7 @@ class Reverse { typename Current, typename Previous > - struct ReversedConcatenate { + struct reversed_concatenate { typedef typename Concatenate< Previous, Cons @@ -40,7 +64,7 @@ class Reverse { }; public: - typedef typename Fold::type type; + typedef typename Fold::type type; }; -- cgit v1.2.3