aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/list/operation/higher/sort.h13
-rw-r--r--test.cc57
2 files changed, 64 insertions, 6 deletions
diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h
index 0ff5c40..a707a15 100644
--- a/src/list/operation/higher/sort.h
+++ b/src/list/operation/higher/sort.h
@@ -1,8 +1,9 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_SORT_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_SORT_H_
-#include "filter.h"
#include "list/operation/concatenate.h"
+#include "list/operation/higher/partition.h"
+#include "function/apply.h"
namespace tav {
@@ -20,11 +21,13 @@ class Sort {
typename Drop<Add<index, Size<1>>, Sequence>::type
>::type;
- template <typename X>
- using comparator_wrapper = Comparator<pivot, X>;
+ using partitions = typename Partition<
+ Apply<Comparator, pivot, tav::_0>::template single_type,
+ sequence_sans_pivot
+ >::type;
- using lhs = typename Filter<comparator_wrapper, sequence_sans_pivot>::type;
- using rhs = typename Remove<comparator_wrapper, sequence_sans_pivot>::type;
+ using lhs = typename Car<partitions>::type;
+ using rhs = typename Cdr<partitions>::type;
public:
typedef typename Concatenate<
diff --git a/test.cc b/test.cc
index 0dafcb8..3b35cd3 100644
--- a/test.cc
+++ b/test.cc
@@ -302,6 +302,26 @@ static_assert(
"(list void 1 void 2 void) != '(1 . 2)"
);
+static_assert(
+ std::is_same<
+ tav::Int<1>,
+ tav::Head<
+ tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type
+ >
+ >::value,
+ "(head (list 1 2 3) != 1"
+);
+
+static_assert(
+ std::is_same<
+ tav::Pair<tav::Int<2>, tav::Pair<tav::Int<3>, void>>,
+ tav::Tail<
+ tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type
+ >
+ >::value,
+ "(tail (list 1 2 3) != '(2 . 3)"
+);
+
// list of type
static_assert(
@@ -377,6 +397,30 @@ static_assert(
"(nth 1 (list 1 2)) != 2"
);
+static_assert(
+ std::is_same<
+ tav::Int<1>,
+ tav::First<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>
+ >::value,
+ "(first (list 1 2 3)) != 1"
+);
+
+static_assert(
+ std::is_same<
+ tav::Int<2>,
+ tav::Second<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>
+ >::value,
+ "(second (list 1 2 3)) != 2"
+);
+
+static_assert(
+ std::is_same<
+ tav::Int<3>,
+ tav::Third<tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type>
+ >::value,
+ "(third (list 1 2 3)) != 3"
+);
+
// list take
static_assert(
@@ -558,7 +602,7 @@ static_assert(
tav::Pair<
tav::List<tav::Int<1>, tav::Int<3>>::type,
tav::List<tav::Int<2>>::type
- >,
+ >::type,
tav::Partition<
tav::Odd,
tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>>::type
@@ -921,6 +965,17 @@ static_assert(
"(sort < (list 1 3 2)) != (list 3 2 1)"
);
+static_assert(
+ std::is_same<
+ tav::Iota<tav::Size<42>, tav::Int<1>, tav::Int<1>>::type,
+ tav::Sort<
+ tav::GreaterThan,
+ tav::Iota<tav::Size<42>, tav::Int<42>, tav::Int<-1>>::type
+ >::type
+ >::value,
+ "(sort > (iota 42 42 -1)) != (iota 42 1 1)"
+);
+
// function apply
static_assert(