diff options
author | Adrian Kummerlaender | 2015-02-17 22:47:56 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2015-02-17 22:47:56 +0100 |
commit | af5662781840ac45c21cbf14cbc7973bcf39d1da (patch) | |
tree | 9264a8e75ea7d87319f4298d47e97c47c58813fb /src/utility | |
parent | c31731d0131c08c4ced091449764561eb3e5e2ab (diff) | |
download | TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar.gz TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar.bz2 TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar.lz TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar.xz TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.tar.zst TypeAsValue-af5662781840ac45c21cbf14cbc7973bcf39d1da.zip |
Reimplemented `TakeWhile` and `DropWhile` in terms of `ListIndex`
* new higher order list operation `ListIndex` returns the index of the first list element satisfying a given predicate function
** this enables finding the split index required for both `TakeWhile` and `DropWhile`
** actual list manipulation is then performed using lower order `Take` or `Drop`
** analogously to `list-index` in SRFI-1
** added appropriate test case
* added higher order predicate utility function `utility::predicate_assurance`
** as its name implies this function enables assuring that a value satisfies a given predicate
*** if this is not the case a surrogate value is returned instead
** this is used to return a appropriate size value if the `ListIndex` call fails because no element satisfies its predicate
** `detail::predicate_negator` was moved from `Remove`'s implementation details into the newly introduced `utility` namespace
*** as it is required by both `TakeWhile` and `DropWhile` in addition to `Remove`
* continuation of 8e49cc6
Diffstat (limited to 'src/utility')
-rw-r--r-- | src/utility/predicate.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utility/predicate.h b/src/utility/predicate.h new file mode 100644 index 0000000..f06fcee --- /dev/null +++ b/src/utility/predicate.h @@ -0,0 +1,34 @@ +#ifndef TYPEASVALUE_SRC_UTILITY_PREDICATE_H_ +#define TYPEASVALUE_SRC_UTILITY_PREDICATE_H_ + +#include "conditional/if.h" +#include "operation/logic.h" + +namespace tav { + +namespace utility { + +template < + template<typename> class Predicate, + typename Surrogate +> +struct predicate_assurance { + template <typename Value> + using assure = If< + Eval<Predicate<Value>>, + Value, + Surrogate + >; +}; + +template <template<typename> class Predicate> +struct predicate_negator { + template <typename Element> + using function = Not<Predicate<Element>>; +}; + +} + +} + +#endif // TYPEASVALUE_SRC_UTILITY_PREDICATE_H_ |