aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-01-31 12:04:34 +0100
committerAdrian Kummerlaender2015-01-31 12:04:34 +0100
commita9ec2e4e13670c8084c6baae59d6f3631960e22c (patch)
tree5d8b519fc516ac7d8c1baff594a8967b71202fdc /src
parent6291f3ce10aa8ebffa895f21c4ccb91b7349c66a (diff)
downloadTypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar.gz
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar.bz2
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar.lz
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar.xz
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.tar.zst
TypeAsValue-a9ec2e4e13670c8084c6baae59d6f3631960e22c.zip
Implemented higher order `Find` list search operation
* added appropriate test case * other queries in `query.h` may be redefined in terms of `Find`
Diffstat (limited to 'src')
-rw-r--r--src/list/operation/higher/find.h30
-rw-r--r--src/list/operation/higher/query.h16
2 files changed, 38 insertions, 8 deletions
diff --git a/src/list/operation/higher/find.h b/src/list/operation/higher/find.h
new file mode 100644
index 0000000..47b88ad
--- /dev/null
+++ b/src/list/operation/higher/find.h
@@ -0,0 +1,30 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_
+
+#include "type.h"
+#include "conditional/if.h"
+
+namespace tav {
+
+template <
+ template<typename> class Predicate,
+ typename Current
+>
+struct Find {
+ typedef If<
+ Predicate<Head<Current>>::type::value,
+ Head<Current>,
+ typename Find<Predicate, Tail<Current>>::type
+ > type;
+};
+
+template <
+ template<typename> class Predicate
+>
+struct Find<Predicate, void> {
+ typedef Boolean<false> type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_
diff --git a/src/list/operation/higher/query.h b/src/list/operation/higher/query.h
index 198ffa5..d2b8e76 100644
--- a/src/list/operation/higher/query.h
+++ b/src/list/operation/higher/query.h
@@ -9,41 +9,41 @@
namespace tav {
template <
- template<typename> class Function,
+ template<typename> class Predicate,
typename List
>
using Any = Fold<
Or,
Boolean<false>,
- typename Map<Function, List>::type
+ typename Map<Predicate, List>::type
>;
template <
- template<typename> class Function,
+ template<typename> class Predicate,
typename List
>
using All = Fold<
And,
Boolean<true>,
- typename Map<Function, List>::type
+ typename Map<Predicate, List>::type
>;
template <
- template<typename> class Function,
+ template<typename> class Predicate,
typename List
>
using None = Not<
- typename Any<Function, List>::type
+ typename Any<Predicate, List>::type
>;
template <
- template<typename> class Function,
+ template<typename> class Predicate,
typename List
>
using Count = Fold<
Add,
tav::Size<0>,
- typename Map<Function, List>::type
+ typename Map<Predicate, List>::type
>;
}