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/function/detail/apply.h | 7 ++----- 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 ++++++----------------- test.cc | 8 -------- 7 files changed, 49 insertions(+), 79 deletions(-) create mode 100644 src/list/detail/fold_variadic.h diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h index 8d4ef6d..3df80ef 100644 --- a/src/function/detail/apply.h +++ b/src/function/detail/apply.h @@ -37,10 +37,7 @@ struct resolve_placeholder> { }; template -using count_placeholders = Count< - is_placeholder, - tav::List ->; +using count_placeholders = Count>; template < template class Function, @@ -58,7 +55,7 @@ struct apply_variadic { template using function = Function< Eval, + List, Arguments >>... >; 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; } diff --git a/test.cc b/test.cc index efe48f3..074d711 100644 --- a/test.cc +++ b/test.cc @@ -321,14 +321,6 @@ static_assert( "(list 1 2) != '(1 . 2)" ); -static_assert( - std::is_same< - tav::Pair, tav::Pair, void>>, - tav::List, void, tav::Int<2>, void> - >::value, - "(list void 1 void 2 void) != '(1 . 2)" -); - static_assert( std::is_same< tav::Int<1>, -- cgit v1.2.3