From 324988569183e38e9c5e42318571693a6fcd9569 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 16 Feb 2015 14:03:53 +0100 Subject: Simplified `List`, `Length` and `Reverse` implementations * continuation of 8e49cc6 * list constructor was generalized to a _variadic fold_ --- src/list/detail/fold_variadic.h | 34 ++++++++++++++++++++++++++++++++++ src/list/list.h | 38 ++------------------------------------ src/list/operation/basic.h | 14 +++----------- src/list/operation/higher/sort.h | 4 ++-- src/list/operation/reverse.h | 23 ++++++----------------- 5 files changed, 47 insertions(+), 66 deletions(-) create mode 100644 src/list/detail/fold_variadic.h (limited to 'src/list') diff --git a/src/list/detail/fold_variadic.h b/src/list/detail/fold_variadic.h new file mode 100644 index 0000000..e02b604 --- /dev/null +++ b/src/list/detail/fold_variadic.h @@ -0,0 +1,34 @@ +#ifndef TYPEASVALUE_SRC_LIST_DETAIL_FOLD_VARIADIC_H_ +#define TYPEASVALUE_SRC_LIST_DETAIL_FOLD_VARIADIC_H_ + +#include "type.h" + +namespace tav { + +namespace detail { + +template < + template class Function, + typename Head, + typename... Tail +> +struct fold_variadic { + typedef Function< + Head, + Eval> + > type; +}; + +template < + template class Function, + typename Head +> +struct fold_variadic { + typedef Function type; +}; + +} + +} + +#endif // TYPEASVALUE_SRC_LIST_DETAIL_FOLD_VARIADIC_H_ diff --git a/src/list/list.h b/src/list/list.h index c9e6a9e..1a4c260 100644 --- a/src/list/list.h +++ b/src/list/list.h @@ -2,46 +2,12 @@ #define TYPEASVALUE_SRC_LIST_LIST_H_ #include "cons.h" +#include "detail/fold_variadic.h" namespace tav { -namespace detail { - -template < - typename Head, - typename... Tail -> -struct List { - typedef Eval> - >> type; -}; - -template -struct List { - typedef Eval> type; -}; - -template -struct List { - typedef Eval> type; -}; - -template -struct List { - typedef Eval> type; -}; - -template <> -struct List { - typedef void type; -}; - -} - template -using List = Eval>; +using List = Eval>; template < typename Type, diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index a299938..d0f6212 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -8,21 +8,13 @@ namespace tav { namespace detail { -template -class Length { - private: - template - using accumulate = Add, Accumulated>; - - public: - typedef tav::Fold, List> type; - -}; +template +using length_accumulate = Add, Accumulated>; } template -using Length = Eval>; +using Length = Fold, List>; } diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h index 2976e06..26d99e6 100644 --- a/src/list/operation/higher/sort.h +++ b/src/list/operation/higher/sort.h @@ -29,9 +29,9 @@ class Sort { public: using type = Concatenate< - tav::List< + List< Eval>, - tav::List, + List, Eval> > >; diff --git a/src/list/operation/reverse.h b/src/list/operation/reverse.h index aabba92..6d9237d 100644 --- a/src/list/operation/reverse.h +++ b/src/list/operation/reverse.h @@ -8,27 +8,16 @@ namespace tav { namespace detail { -template -class Reverse { - private: - template < - typename Current, - typename Previous - > - using reversed_append = tav::Append< - Previous, - tav::List - >; - - public: - typedef tav::Fold type; - -}; +template < + typename Current, + typename Previous +> +using reversed_append = tav::Append>; } template -using Reverse = Eval>; +using Reverse = Fold; } -- cgit v1.2.3