aboutsummaryrefslogtreecommitdiff
path: root/src/utility
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-19 13:45:07 +0100
committerAdrian Kummerlaender2015-02-19 13:45:07 +0100
commita8bec66b05eece7b8a39102fb1b0ba8f778eb9fe (patch)
treec1a6c4b1c6cba5ba1d87499a220f76eab59673c3 /src/utility
parent9bb66d9c1d8a7bf5bf02f5a7c400894e928d2a95 (diff)
downloadTypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar.gz
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar.bz2
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar.lz
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar.xz
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.tar.zst
TypeAsValue-a8bec66b05eece7b8a39102fb1b0ba8f778eb9fe.zip
Reimplemented `Find` in terms of `ListIndex`
* `ListIndex` already implements the necessary partial template specializations for finding elements matching a predicate * reimplemented `Cond` using `detail::find_variadic` as `Find` depends on `Apply` which in turn depends on `Cond` ** it is useful if core functionality such as the branched conditional `Cond` do not require higher order functionality such as `Find` *** otherwise one can not use core functionality in the implementation of higher order functionality * introduced `utility::predicate_guard` helper template ** checks a given value using a predicate and only forwards the value to the guarded function if this check is successful ** if check is unsuccessful it returns a surrogate value simmilar to `utility::predicate_assurance`
Diffstat (limited to 'src/utility')
-rw-r--r--src/utility/predicate.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utility/predicate.h b/src/utility/predicate.h
index f06fcee..e84b18f 100644
--- a/src/utility/predicate.h
+++ b/src/utility/predicate.h
@@ -21,6 +21,28 @@ struct predicate_assurance {
>;
};
+template <
+ template<typename...> class Function,
+ typename... Arguments
+>
+struct defer_eval {
+ typedef Function<Arguments...> type;
+};
+
+template <
+ template<typename> class Predicate,
+ template<typename> class Charge,
+ typename Surrogate
+>
+struct predicate_guard {
+ template <typename Value>
+ using check = Eval<If<
+ Eval<Predicate<Value>>,
+ defer_eval<Charge, Value>,
+ Surrogate
+ >>;
+};
+
template <template<typename> class Predicate>
struct predicate_negator {
template <typename Element>