aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/function/apply.h5
-rw-r--r--src/list/list.h2
-rw-r--r--src/list/operation/basic.h72
-rw-r--r--src/list/operation/nth.h31
-rw-r--r--src/list/operation/take.h40
-rw-r--r--test.cc1
6 files changed, 83 insertions, 68 deletions
diff --git a/src/function/apply.h b/src/function/apply.h
index 6012a01..8e780e0 100644
--- a/src/function/apply.h
+++ b/src/function/apply.h
@@ -3,6 +3,9 @@
#include <type_traits>
+#include "list/list.h"
+#include "list/operation/nth.h"
+
namespace tav {
namespace detail {
@@ -45,8 +48,6 @@ template <
typename... Arguments
>
struct Apply {
- typedef typename tav::List<Arguments...>::type argument_list;
-
template <typename... Partials>
using variadic_type = Function<
typename detail::resolve_placeholder<
diff --git a/src/list/list.h b/src/list/list.h
index 5c67872..c03a0ef 100644
--- a/src/list/list.h
+++ b/src/list/list.h
@@ -30,6 +30,8 @@ using Tail = Cdr<Cons>;
}
#include "operation/basic.h"
+#include "operation/nth.h"
+#include "operation/take.h"
#include "operation/append.h"
#include "operation/concatenate.h"
diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h
index d80b347..1f4b043 100644
--- a/src/list/operation/basic.h
+++ b/src/list/operation/basic.h
@@ -1,76 +1,18 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_
-#include "operation/math.h"
#include "higher/fold.h"
+#include "function/apply.h"
+#include "operation/math.h"
namespace tav {
template <typename Cons>
-class Length {
- private:
- template <
- typename,
- typename Previous
- >
- struct count {
- typedef Add<Size<1>, Previous> type;
- };
-
- public:
- typedef typename Fold<count, Size<0>, Cons>::type type;
-
-};
-
-template <
- typename Index,
- typename Cons
->
-struct Nth {
- typedef typename Nth<
- Substract<Index, Size<1>>,
- Tail<Cons>
- >::type type;
-};
-
-template <typename Index>
-struct Nth<Index, void> {
- typedef void type;
-};
-
-template <typename Cons>
-struct Nth<Size<0>, Cons> {
- typedef Head<Cons> type;
-};
-
-template <
- typename Count,
- typename Current
->
-struct Take {
- typedef Cons<
- Head<Current>,
- typename Take<
- Substract<Count, Size<1>>,
- Tail<Current>
- >::type
- > type;
-};
-
-template <typename Current>
-struct Take<Size<0>, Current> {
- typedef void type;
-};
-
-template <typename Count>
-struct Take<Count, void> {
- typedef void type;
-};
-
-template <>
-struct Take<Size<0>, void> {
- typedef void type;
-};
+using Length = Fold<
+ Apply<Add, Size<1>, _1>::pair_type,
+ Size<0>,
+ Cons
+>;
}
diff --git a/src/list/operation/nth.h b/src/list/operation/nth.h
new file mode 100644
index 0000000..8eb88ba
--- /dev/null
+++ b/src/list/operation/nth.h
@@ -0,0 +1,31 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
+
+#include "operation/math.h"
+
+namespace tav {
+
+template <
+ typename Index,
+ typename Cons
+>
+struct Nth {
+ typedef typename Nth<
+ Substract<Index, Size<1>>,
+ Tail<Cons>
+ >::type type;
+};
+
+template <typename Cons>
+struct Nth<Size<0>, Cons> {
+ typedef Head<Cons> type;
+};
+
+template <typename Index>
+struct Nth<Index, void> {
+ typedef void type;
+};
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_NTH_H_
diff --git a/src/list/operation/take.h b/src/list/operation/take.h
new file mode 100644
index 0000000..db25640
--- /dev/null
+++ b/src/list/operation/take.h
@@ -0,0 +1,40 @@
+#ifndef TYPEASVALUE_SRC_LIST_OPERATION_TAKE_H_
+#define TYPEASVALUE_SRC_LIST_OPERATION_TAKE_H_
+
+#include "operation/math.h"
+
+namespace tav {
+
+template <
+ typename Count,
+ typename Current
+>
+struct Take {
+ typedef Cons<
+ Head<Current>,
+ typename Take<
+ Substract<Count, Size<1>>,
+ Tail<Current>
+ >::type
+ > type;
+};
+
+template <typename Current>
+struct Take<Size<0>, Current> {
+ typedef void type;
+};
+
+template <typename Count>
+struct Take<Count, void> {
+ typedef void type;
+};
+
+template <>
+struct Take<Size<0>, void> {
+ typedef void type;
+};
+
+
+}
+
+#endif // TYPEASVALUE_SRC_LIST_OPERATION_TAKE_H_
diff --git a/test.cc b/test.cc
index 0c16126..33d0248 100644
--- a/test.cc
+++ b/test.cc
@@ -7,7 +7,6 @@
#include "list/list.h"
#include "list/operation/reverse.h"
#include "list/operation/contains.h"
-#include "list/operation/higher/fold.h"
#include "list/operation/higher/misc.h"
#include "list/operation/higher/query.h"
#include "list/generator/iota.h"