aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/list/operation/higher/drop_while.h42
-rw-r--r--src/list/operation/higher/list_index.h45
-rw-r--r--src/list/operation/higher/remove.h13
-rw-r--r--src/list/operation/higher/take_while.h45
-rw-r--r--src/utility/predicate.h34
5 files changed, 113 insertions, 66 deletions
diff --git a/src/list/operation/higher/drop_while.h b/src/list/operation/higher/drop_while.h
index 021698f..1207020 100644
--- a/src/list/operation/higher/drop_while.h
+++ b/src/list/operation/higher/drop_while.h
@@ -1,38 +1,28 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_
-#include "conditional/if.h"
+#include "list_index.h"
+#include "list/operation/drop.h"
+#include "utility/predicate.h"
namespace tav {
-namespace detail {
-
-template <
- template<typename> class Predicate,
- typename Current
->
-struct DropWhile {
- typedef If<
- Eval<Predicate<Head<Current>>>,
- Eval<DropWhile<Predicate, Tail<Current>>>,
- Current
- > type;
-};
-
-template <
- template<typename> class Predicate
->
-struct DropWhile<Predicate, void> {
- typedef void type;
-};
-
-}
-
template <
template<typename> class Predicate,
- typename Current
+ typename List
>
-using DropWhile = Eval<detail::DropWhile<Predicate, Current>>;
+using DropWhile = Drop<
+ typename utility::predicate_assurance<
+ utility::predicate_negator<std::is_void>::template function,
+ Length<List>
+ >::template assure<
+ ListIndex<
+ utility::predicate_negator<Predicate>::template function,
+ List
+ >
+ >,
+ List
+>;
}
diff --git a/src/list/operation/higher/list_index.h b/src/list/operation/higher/list_index.h
new file mode 100644
index 0000000..bbf43ee
--- /dev/null
+++ b/src/list/operation/higher/list_index.h
@@ -0,0 +1,45 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_
+
+#include "operation/math.h"
+
+namespace tav {
+
+namespace detail {
+
+template <
+ template<typename> class Predicate,
+ typename List,
+ typename Index = Size<0>
+>
+struct index_of_first {
+ typedef If<
+ Eval<Predicate<Head<List>>>,
+ Index,
+ Eval<index_of_first<
+ Predicate,
+ Tail<List>,
+ Add<Index, Size<1>>
+ >>
+ > type;
+};
+
+template <
+ template<typename> class Predicate,
+ typename Index
+>
+struct index_of_first<Predicate, void, Index> {
+ typedef void type;
+};
+
+}
+
+template <
+ template<typename> class Predicate,
+ typename List
+>
+using ListIndex = Eval<detail::index_of_first<Predicate, List>>;
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_LIST_INDEX_H_
diff --git a/src/list/operation/higher/remove.h b/src/list/operation/higher/remove.h
index 598f5a6..6770359 100644
--- a/src/list/operation/higher/remove.h
+++ b/src/list/operation/higher/remove.h
@@ -2,25 +2,16 @@
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_REMOVE_H_
#include "filter.h"
+#include "utility/predicate.h"
namespace tav {
-namespace detail {
-
-template <template<typename> class Predicate>
-struct predicate_negator {
- template <typename Element>
- using function = Not<Predicate<Element>>;
-};
-
-}
-
template <
template<typename> class Predicate,
typename List
>
using Remove = Filter<
- detail::predicate_negator<Predicate>::template function,
+ utility::predicate_negator<Predicate>::template function,
List
>;
diff --git a/src/list/operation/higher/take_while.h b/src/list/operation/higher/take_while.h
index dec5551..f9fc3aa 100644
--- a/src/list/operation/higher/take_while.h
+++ b/src/list/operation/higher/take_while.h
@@ -1,41 +1,28 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_
-#include "conditional/if.h"
+#include "list_index.h"
+#include "list/operation/take.h"
+#include "utility/predicate.h"
namespace tav {
-namespace detail {
-
-template <
- template<typename> class Predicate,
- typename Current
->
-struct TakeWhile {
- typedef If<
- Eval<Predicate<Head<Current>>>,
- Cons<
- Head<Current>,
- Eval<TakeWhile<Predicate, Tail<Current>>>
- >,
- void
- > type;
-};
-
-template <
- template<typename> class Predicate
->
-struct TakeWhile<Predicate, void> {
- typedef void type;
-};
-
-}
-
template <
template<typename> class Predicate,
- typename Current
+ typename List
>
-using TakeWhile = Eval<detail::TakeWhile<Predicate, Current>>;
+using TakeWhile = Take<
+ typename utility::predicate_assurance<
+ utility::predicate_negator<std::is_void>::template function,
+ Length<List>
+ >::template assure<
+ ListIndex<
+ utility::predicate_negator<Predicate>::template function,
+ List
+ >
+ >,
+ List
+>;
}
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_