diff options
Diffstat (limited to 'src/list')
-rw-r--r-- | src/list/operation/higher/filter.h | 22 | ||||
-rw-r--r-- | src/list/operation/higher/map.h | 1 | ||||
-rw-r--r-- | src/list/operation/higher/partition.h | 21 |
3 files changed, 39 insertions, 5 deletions
diff --git a/src/list/operation/higher/filter.h b/src/list/operation/higher/filter.h index 8788aed..d91735e 100644 --- a/src/list/operation/higher/filter.h +++ b/src/list/operation/higher/filter.h @@ -7,7 +7,7 @@ namespace tav { template < - template<typename> class Function, + template<typename> class Predicate, typename List > class Filter { @@ -16,16 +16,30 @@ class Filter { typename Current, typename Previous > - struct function_wrapper { + struct predicate_wrapper { typedef If< - Function<Current>::type::value, + Predicate<Current>::type::value, Cons<Current, Previous>, Previous > type; }; public: - typedef typename Fold<function_wrapper, void, List>::type type; + typedef typename Fold<predicate_wrapper, void, List>::type type; + +}; + +template < + template<typename> class Predicate, + typename List +> +class Remove { + private: + template <typename Element> + using predicate_negator = Not<Predicate<Element>>; + + public: + typedef typename Filter<predicate_negator, List>::type type; }; diff --git a/src/list/operation/higher/map.h b/src/list/operation/higher/map.h index 1c577ca..a451b2a 100644 --- a/src/list/operation/higher/map.h +++ b/src/list/operation/higher/map.h @@ -2,7 +2,6 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_MAP_H_ #include "fold.h" -#include "conditional/if.h" namespace tav { diff --git a/src/list/operation/higher/partition.h b/src/list/operation/higher/partition.h new file mode 100644 index 0000000..e42b971 --- /dev/null +++ b/src/list/operation/higher/partition.h @@ -0,0 +1,21 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_PARTITION_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_PARTITION_H_ + +#include "filter.h" + +namespace tav { + +template < + template<typename> class Predicate, + typename List +> +struct Partition { + typedef Cons< + typename Filter<Predicate, List>::type, + typename Remove<Predicate, List>::type + > type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_PARTITION_H_ |