aboutsummaryrefslogtreecommitdiff
path: root/test.cc
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-17 22:47:56 +0100
committerAdrian Kummerlaender2015-02-17 22:47:56 +0100
commitaf5662781840ac45c21cbf14cbc7973bcf39d1da (patch)
tree9264a8e75ea7d87319f4298d47e97c47c58813fb /test.cc
parentc31731d0131c08c4ced091449764561eb3e5e2ab (diff)
downloadTypeAsValue-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 'test.cc')
-rw-r--r--test.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/test.cc b/test.cc
index 2f95561..6a957b1 100644
--- a/test.cc
+++ b/test.cc
@@ -12,6 +12,7 @@
#include "list/operation/higher/remove.h"
#include "list/operation/higher/partition.h"
#include "list/operation/higher/query.h"
+#include "list/operation/higher/list_index.h"
#include "list/operation/higher/find.h"
#include "list/operation/higher/take_while.h"
#include "list/operation/higher/drop_while.h"
@@ -906,6 +907,30 @@ static_assert(
"(count even? (list 1 3 5)) != 0"
);
+// list index
+
+static_assert(
+ std::is_same<
+ tav::Size<2>,
+ tav::ListIndex<
+ tav::Even,
+ tav::List<tav::Int<1>, tav::Int<3>, tav::Int<4>, tav::Int<6>>
+ >
+ >::value,
+ "(list-index even? (list 1 3 4 6)) != 2"
+);
+
+static_assert(
+ std::is_same<
+ void,
+ tav::ListIndex<
+ tav::Even,
+ tav::List<tav::Int<1>, tav::Int<3>, tav::Int<5>>
+ >
+ >::value,
+ "(list-index even? (list 1 3 5)) != void"
+);
+
// list find
static_assert(