From cb1ee55373e5efd1441664ec4e6942d4ace5e368 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 21 Jan 2015 16:55:17 +0100 Subject: Implemented `Contains` in terms of `Any` * as its name implies this _function_ simplifies checking if a specific value is contained within a given list * updated `Map` to actually resolve the provided _function_ --- src/list/operation/contains.h | 26 ++++++++++++++++++++++++++ src/list/operation/higher/misc.h | 5 ++++- src/list/operation/higher/query.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/list/operation/contains.h (limited to 'src/list') diff --git a/src/list/operation/contains.h b/src/list/operation/contains.h new file mode 100644 index 0000000..9e752ed --- /dev/null +++ b/src/list/operation/contains.h @@ -0,0 +1,26 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_CONTAINS_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_CONTAINS_H_ + +#include "higher/query.h" + +namespace tav { + +template < + typename Element, + typename List +> +class Contains { + private: + template + struct comparator { + typedef std::is_same type; + }; + + public: + typedef typename Any::type type; + +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_CONTAINS_H_ diff --git a/src/list/operation/higher/misc.h b/src/list/operation/higher/misc.h index 1eacaaa..feec7de 100644 --- a/src/list/operation/higher/misc.h +++ b/src/list/operation/higher/misc.h @@ -17,7 +17,10 @@ class Map { typename Previous > struct function_wrapper { - typedef Cons, Previous> type; + typedef Cons< + typename Function::type, + Previous + > type; }; public: diff --git a/src/list/operation/higher/query.h b/src/list/operation/higher/query.h index 34d05cb..29f65dc 100644 --- a/src/list/operation/higher/query.h +++ b/src/list/operation/higher/query.h @@ -2,6 +2,7 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_QUERY_H_ #include "fold.h" +#include "misc.h" #include "operation/logic.h" namespace tav { -- cgit v1.2.3