From e317b6c9318766eabda53d9dc6e9cdac55aae34b Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 1 Feb 2015 12:57:22 +0100 Subject: 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 --- src/list/operation/higher/take_while.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/list/operation/higher/take_while.h (limited to 'src') 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 class Predicate, + typename Current +> +struct TakeWhile { + typedef If< + Predicate>::type::value, + Cons< + Head, + typename TakeWhile>::type + >, + void + > type; +}; + +template < + template class Predicate +> +struct TakeWhile { + typedef void type; +}; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_ -- cgit v1.2.3