From a3cfc224111c324324e29a9a7a61b511053ec14c Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 18 Feb 2015 20:23:35 +0100 Subject: Reimplemented `Append` in terms of `Fold` * `Fold` already implements the necessary partial specializations for traversing list structures --- src/list/operation/append.h | 40 ++++++++++++++++++++++------------------ src/list/operation/concatenate.h | 1 + src/list/operation/reverse.h | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src/list') 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, - Eval, - Secondary - >> - > type; -}; - -template -struct Append { - typedef Secondary type; +template +struct replace_void_cdr { + template + using function = Cons< + CAR, + If< + Eval>, + Replacement, + CDR + > + >; }; } @@ -30,7 +26,15 @@ template < typename Primary, typename Secondary > -using Append = Eval>; +using Append = If< + Eval>, + Secondary, + Fold< + detail::replace_void_cdr::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>; +using reversed_append = Append>; } -- cgit v1.2.3