aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-01 12:57:22 +0100
committerAdrian Kummerlaender2015-02-01 12:57:22 +0100
commite317b6c9318766eabda53d9dc6e9cdac55aae34b (patch)
treeb4875ba3be499d8c5cb03307496e56c268b4f440 /src
parenta9ec2e4e13670c8084c6baae59d6f3631960e22c (diff)
downloadTypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar.gz
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar.bz2
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar.lz
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar.xz
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.tar.zst
TypeAsValue-e317b6c9318766eabda53d9dc6e9cdac55aae34b.zip
Added `TakeWhile` higher order list operation
* as its name implies this function returns the longest initial prefix of a list that satisfies a given _Predicate_ * added appropriate test case
Diffstat (limited to 'src')
-rw-r--r--src/list/operation/higher/take_while.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/list/operation/higher/take_while.h b/src/list/operation/higher/take_while.h
new file mode 100644
index 0000000..01062f4
--- /dev/null
+++ b/src/list/operation/higher/take_while.h
@@ -0,0 +1,33 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
+
+#include "type.h"
+#include "conditional/if.h"
+
+namespace tav {
+
+template <
+ template<typename> class Predicate,
+ typename Current
+>
+struct TakeWhile {
+ typedef If<
+ Predicate<Head<Current>>::type::value,
+ Cons<
+ Head<Current>,
+ typename TakeWhile<Predicate, Tail<Current>>::type
+ >,
+ void
+ > type;
+};
+
+template <
+ template<typename> class Predicate
+>
+struct TakeWhile<Predicate, void> {
+ typedef void type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_