aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-21 16:55:17 +0100
committerAdrian Kummerlaender2015-01-21 16:55:17 +0100
commitcb1ee55373e5efd1441664ec4e6942d4ace5e368 (patch)
tree07b29541c603d2d716627e91b39e8e03ce23e4da
parent611150b033340ed7433d6ba2482f86aa5655bd15 (diff)
downloadTypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar.gz
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar.bz2
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar.lz
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar.xz
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.tar.zst
TypeAsValue-cb1ee55373e5efd1441664ec4e6942d4ace5e368.zip
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_
-rw-r--r--src/list/operation/contains.h26
-rw-r--r--src/list/operation/higher/misc.h5
-rw-r--r--src/list/operation/higher/query.h1
-rw-r--r--test.cc25
4 files changed, 56 insertions, 1 deletions
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 <typename Current>
+ struct comparator {
+ typedef std::is_same<Current, Element> type;
+ };
+
+ public:
+ typedef typename Any<comparator, List>::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<Function<Current>, Previous> type;
+ typedef Cons<
+ typename Function<Current>::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 {
diff --git a/test.cc b/test.cc
index 49b95cb..718fb70 100644
--- a/test.cc
+++ b/test.cc
@@ -6,6 +6,7 @@
#include "list/cons.h"
#include "list/list.h"
#include "list/operation/reverse.h"
+#include "list/operation/contains.h"
#include "list/operation/higher/fold.h"
#include "list/operation/higher/misc.h"
#include "list/operation/higher/query.h"
@@ -466,3 +467,27 @@ static_assert(
>::value,
"(none even? (list 2 3 5)) != #f"
);
+
+// list contains
+
+static_assert(
+ std::is_same<
+ tav::Boolean<true>,
+ tav::Contains<
+ tav::Int<2>,
+ tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type
+ >::type
+ >::value,
+ "(contains 2 (list 1 2 3)) != #t"
+);
+
+static_assert(
+ std::is_same<
+ tav::Boolean<false>,
+ tav::Contains<
+ tav::Int<0>,
+ tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type
+ >::type
+ >::value,
+ "(contains 0 (list 1 2 3)) != #f"
+);