aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/conditional/cond.h12
-rw-r--r--src/list/operation/concatenate.h13
-rw-r--r--src/list/operation/higher/sort.h8
-rw-r--r--test.cc12
4 files changed, 32 insertions, 13 deletions
diff --git a/src/conditional/cond.h b/src/conditional/cond.h
index ca5e46d..4def611 100644
--- a/src/conditional/cond.h
+++ b/src/conditional/cond.h
@@ -9,12 +9,14 @@ namespace tav {
namespace detail {
-template <typename Pair>
-using cond_predicate = IsTrue<Car<Pair>>;
-
template <typename... Branches>
-struct select_cond_branch {
- using type = Eval<detail::find_variadic<detail::cond_predicate, Branches...>>;
+class select_cond_branch {
+ private:
+ template <typename Pair>
+ using predicate = IsTrue<Car<Pair>>;
+
+ public:
+ using type = Eval<detail::find_variadic<predicate, Branches...>>;
static_assert(
IsPair<type>::value,
diff --git a/src/list/operation/concatenate.h b/src/list/operation/concatenate.h
index a5cbaa6..cf680c1 100644
--- a/src/list/operation/concatenate.h
+++ b/src/list/operation/concatenate.h
@@ -2,16 +2,23 @@
#define TYPEASVALUE_SRC_LIST_OPERATION_CONCATENATE_H_
#include "append.h"
-#include "higher/remove.h"
#include "higher/fold.h"
+#include "conditional/if.h"
namespace tav {
-template <typename ListOfLists>
+template <
+ typename Head,
+ typename... Tail
+>
using Concatenate = Fold<
Append,
void,
- ListOfLists
+ If<
+ Boolean<sizeof...(Tail) == 0>,
+ Head,
+ List<Head, Tail...>
+ >
>;
}
diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h
index 925ab89..51317fa 100644
--- a/src/list/operation/higher/sort.h
+++ b/src/list/operation/higher/sort.h
@@ -29,11 +29,9 @@ class quick_sort {
public:
using type = Concatenate<
- List<
- Eval<quick_sort<Comparator, lhs>>,
- List<pivot>,
- Eval<quick_sort<Comparator, rhs>>
- >
+ Eval<quick_sort<Comparator, lhs>>,
+ List<pivot>,
+ Eval<quick_sort<Comparator, rhs>>
>;
};
diff --git a/test.cc b/test.cc
index 525afcf..ef0d8c3 100644
--- a/test.cc
+++ b/test.cc
@@ -839,6 +839,18 @@ static_assert(
"(concatenate (list (list 1 2) (list 3) (list 4 5 6))) != (list 1 2 3 4 5 6)"
);
+static_assert(
+ std::is_same<
+ tav::List<tav::Int<1>, tav::Int<2>, tav::Int<3>, tav::Int<4>, tav::Int<5>, tav::Int<6>>,
+ tav::Concatenate<
+ tav::List<tav::Int<1>, tav::Int<2>>,
+ tav::List<tav::Int<3>>,
+ tav::List<tav::Int<4>, tav::Int<5>, tav::Int<6>>
+ >
+ >::value,
+ "(concatenate (list 1 2) (list 3) (list 4 5 6)) != (list 1 2 3 4 5 6)"
+);
+
// list iota
static_assert(