aboutsummaryrefslogtreecommitdiff
path: root/src/list
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-02-18 20:23:35 +0100
committerAdrian Kummerlaender2015-02-18 20:23:35 +0100
commita3cfc224111c324324e29a9a7a61b511053ec14c (patch)
tree64c92507ee353e64b00597460d428ad4c84e7b14 /src/list
parentaf5662781840ac45c21cbf14cbc7973bcf39d1da (diff)
downloadTypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar.gz
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar.bz2
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar.lz
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar.xz
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.tar.zst
TypeAsValue-a3cfc224111c324324e29a9a7a61b511053ec14c.zip
Reimplemented `Append` in terms of `Fold`
* `Fold` already implements the necessary partial specializations for traversing list structures
Diffstat (limited to 'src/list')
-rw-r--r--src/list/operation/append.h40
-rw-r--r--src/list/operation/concatenate.h1
-rw-r--r--src/list/operation/reverse.h2
3 files changed, 24 insertions, 19 deletions
diff --git a/src/list/operation/append.h b/src/list/operation/append.h
index 2dcd184..77f72d9 100644
--- a/src/list/operation/append.h
+++ b/src/list/operation/append.h
@@ -1,27 +1,23 @@
#ifndef TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_
#define TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_
+#include "higher/fold.h"
+
namespace tav {
namespace detail {
-template <
- typename Primary,
- typename Secondary
->
-struct Append {
- typedef Cons<
- Head<Primary>,
- Eval<Append<
- Tail<Primary>,
- Secondary
- >>
- > type;
-};
-
-template <typename Secondary>
-struct Append<void, Secondary> {
- typedef Secondary type;
+template <typename Replacement>
+struct replace_void_cdr {
+ template <typename CAR, typename CDR>
+ using function = Cons<
+ CAR,
+ If<
+ Eval<std::is_void<CDR>>,
+ Replacement,
+ CDR
+ >
+ >;
};
}
@@ -30,7 +26,15 @@ template <
typename Primary,
typename Secondary
>
-using Append = Eval<detail::Append<Primary, Secondary>>;
+using Append = If<
+ Eval<std::is_void<Primary>>,
+ Secondary,
+ Fold<
+ detail::replace_void_cdr<Secondary>::template function,
+ void,
+ Primary
+ >
+>;
}
diff --git a/src/list/operation/concatenate.h b/src/list/operation/concatenate.h
index 944470b..a5cbaa6 100644
--- a/src/list/operation/concatenate.h
+++ b/src/list/operation/concatenate.h
@@ -2,6 +2,7 @@
#define TYPEASVALUE_SRC_LIST_OPERATION_CONCATENATE_H_
#include "append.h"
+#include "higher/remove.h"
#include "higher/fold.h"
namespace tav {
diff --git a/src/list/operation/reverse.h b/src/list/operation/reverse.h
index 6d9237d..cabc229 100644
--- a/src/list/operation/reverse.h
+++ b/src/list/operation/reverse.h
@@ -12,7 +12,7 @@ template <
typename Current,
typename Previous
>
-using reversed_append = tav::Append<Previous, List<Current>>;
+using reversed_append = Append<Previous, List<Current>>;
}