From 46e174935b122c0da4b51532a7f683a512eeaf65 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 15 Feb 2015 14:07:50 +0100 Subject: Moved class-based implementations into `detail` namespace * while class templates enable e.g. hiding implementation details they also require evaluation via `Eval` ** this clutters up the actual logic and is now hidden behind aliae that perform the evaluation --- src/list/operation/append.h | 14 ++++++++++++-- src/list/operation/basic.h | 15 +++++++++------ src/list/operation/delete_nth.h | 4 ++-- src/list/operation/drop.h | 9 +++++++++ src/list/operation/higher/drop_while.h | 14 ++++++++++++-- src/list/operation/higher/filter.h | 18 +++++++----------- src/list/operation/higher/find.h | 14 ++++++++++++-- src/list/operation/higher/fold.h | 15 +++++++++++++-- src/list/operation/higher/map.h | 12 +++++++++++- src/list/operation/higher/partition.h | 5 +++-- src/list/operation/higher/query.h | 12 +++++------- src/list/operation/higher/remove.h | 34 ++++++++++++++++++++++++++++++++++ src/list/operation/higher/sort.h | 34 ++++++++++++++++++++++------------ src/list/operation/higher/take_while.h | 18 ++++++++++++++---- src/list/operation/nth.h | 26 ++++++++++++++++++-------- src/list/operation/reverse.h | 13 ++++++++++--- src/list/operation/take.h | 13 +++++++++++-- 17 files changed, 204 insertions(+), 66 deletions(-) create mode 100644 src/list/operation/higher/remove.h (limited to 'src/list/operation') diff --git a/src/list/operation/append.h b/src/list/operation/append.h index 28c9adf..2dcd184 100644 --- a/src/list/operation/append.h +++ b/src/list/operation/append.h @@ -3,18 +3,20 @@ namespace tav { +namespace detail { + template < typename Primary, typename Secondary > struct Append { - typedef Eval, Eval, Secondary >> - >> type; + > type; }; template @@ -24,4 +26,12 @@ struct Append { } +template < + typename Primary, + typename Secondary +> +using Append = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_APPEND_H_ diff --git a/src/list/operation/basic.h b/src/list/operation/basic.h index 5f9a3f9..a299938 100644 --- a/src/list/operation/basic.h +++ b/src/list/operation/basic.h @@ -6,21 +6,24 @@ namespace tav { -template +namespace detail { + +template class Length { private: template using accumulate = Add, Accumulated>; public: - typedef Eval, - Cons - >> type; + typedef tav::Fold, List> type; }; } +template +using Length = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_BASIC_H_ diff --git a/src/list/operation/delete_nth.h b/src/list/operation/delete_nth.h index 6127ade..18e52bf 100644 --- a/src/list/operation/delete_nth.h +++ b/src/list/operation/delete_nth.h @@ -12,8 +12,8 @@ template < typename List > using DeleteNth = Append< - Eval>, - Eval>, List>> + Take, + Drop>, List> >; } diff --git a/src/list/operation/drop.h b/src/list/operation/drop.h index c61983b..c7745d7 100644 --- a/src/list/operation/drop.h +++ b/src/list/operation/drop.h @@ -5,6 +5,8 @@ namespace tav { +namespace detail { + template < typename Count, typename Current @@ -31,6 +33,13 @@ struct Drop, void> { typedef void type; }; +} + +template < + typename Count, + typename Current +> +using Drop = Eval>; } diff --git a/src/list/operation/higher/drop_while.h b/src/list/operation/higher/drop_while.h index 8ba2664..021698f 100644 --- a/src/list/operation/higher/drop_while.h +++ b/src/list/operation/higher/drop_while.h @@ -5,16 +5,18 @@ namespace tav { +namespace detail { + template < template class Predicate, typename Current > struct DropWhile { - typedef Eval>>, Eval>>, Current - >> type; + > type; }; template < @@ -26,4 +28,12 @@ struct DropWhile { } +template < + template class Predicate, + typename Current +> +using DropWhile = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_DROP_WHILE_H_ diff --git a/src/list/operation/higher/filter.h b/src/list/operation/higher/filter.h index 3588400..17d49c2 100644 --- a/src/list/operation/higher/filter.h +++ b/src/list/operation/higher/filter.h @@ -6,6 +6,8 @@ namespace tav { +namespace detail { + template < template class Predicate, typename List @@ -18,28 +20,22 @@ class Filter { > using predicate_wrapper = If< Eval>, - Eval>, + Cons, Previous >; public: - typedef Eval> type; + typedef tav::Fold type; }; +} + template < template class Predicate, typename List > -class Remove { - private: - template - using predicate_negator = Not>; - - public: - typedef Eval> type; - -}; +using Filter = Eval>; } diff --git a/src/list/operation/higher/find.h b/src/list/operation/higher/find.h index abc3199..48533b7 100644 --- a/src/list/operation/higher/find.h +++ b/src/list/operation/higher/find.h @@ -6,16 +6,18 @@ namespace tav { +namespace detail { + template < template class Predicate, typename Current > struct Find { - typedef Eval>>, Head, Eval>> - >> type; + > type; }; template < @@ -27,4 +29,12 @@ struct Find { } +template < + template class Predicate, + typename List +> +using Find = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FIND_H_ diff --git a/src/list/operation/higher/fold.h b/src/list/operation/higher/fold.h index 3ed0a42..7364fe5 100644 --- a/src/list/operation/higher/fold.h +++ b/src/list/operation/higher/fold.h @@ -3,16 +3,18 @@ namespace tav { +namespace detail { + template < template class Function, typename Initial, typename Current > struct Fold { - typedef Eval, Eval>> - >> type; + > type; }; template < @@ -25,4 +27,13 @@ struct Fold { } +template < + template class Function, + typename Initial, + typename Current +> +using Fold = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_FOLD_H_ diff --git a/src/list/operation/higher/map.h b/src/list/operation/higher/map.h index ac214b7..cc30355 100644 --- a/src/list/operation/higher/map.h +++ b/src/list/operation/higher/map.h @@ -5,6 +5,8 @@ namespace tav { +namespace detail { + template < template class Function, typename List @@ -21,10 +23,18 @@ class Map { >; public: - typedef Eval> type; + using type = tav::Fold; }; } +template < + template class Function, + typename List +> +using Map = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_MAP_H_ diff --git a/src/list/operation/higher/partition.h b/src/list/operation/higher/partition.h index eedeb91..ee49fcc 100644 --- a/src/list/operation/higher/partition.h +++ b/src/list/operation/higher/partition.h @@ -2,6 +2,7 @@ #define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_PARTITION_H_ #include "filter.h" +#include "remove.h" namespace tav { @@ -10,8 +11,8 @@ template < typename Elements > using Partition = Cons< - Eval>, - Eval> + Filter, + Remove >; } diff --git a/src/list/operation/higher/query.h b/src/list/operation/higher/query.h index 1d00267..c6c73f4 100644 --- a/src/list/operation/higher/query.h +++ b/src/list/operation/higher/query.h @@ -15,7 +15,7 @@ template < using Any = Fold< Or, Boolean, - Eval> + Map >; template < @@ -25,16 +25,14 @@ template < using All = Fold< And, Boolean, - Eval> + Map >; template < template class Predicate, typename List > -using None = Not< - Eval> ->; +using None = Not>; template < template class Predicate, @@ -42,8 +40,8 @@ template < > using Count = Fold< Add, - tav::Size<0>, - Eval> + Size<0>, + Map >; } diff --git a/src/list/operation/higher/remove.h b/src/list/operation/higher/remove.h new file mode 100644 index 0000000..e67e962 --- /dev/null +++ b/src/list/operation/higher/remove.h @@ -0,0 +1,34 @@ +#ifndef TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_REMOVE_H_ +#define TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_REMOVE_H_ + +#include "filter.h" + +namespace tav { + +namespace detail { + +template < + template class Predicate, + typename List +> +class Remove { + private: + template + using predicate_negator = Not>; + + public: + typedef tav::Filter type; + +}; + +} + +template < + template class Predicate, + typename List +> +using Remove = Eval>; + +} + +#endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_REMOVE_H_ diff --git a/src/list/operation/higher/sort.h b/src/list/operation/higher/sort.h index cf86e9b..2976e06 100644 --- a/src/list/operation/higher/sort.h +++ b/src/list/operation/higher/sort.h @@ -8,31 +8,33 @@ namespace tav { +namespace detail { + template < template class Comparator, typename Sequence > class Sort { private: - using index = Divide>, Size<2>>; - using pivot = Eval>; + using index = Divide, Size<2>>; + using pivot = tav::Nth; - using partitions = Eval::template function, - Eval> - >>; + DeleteNth + >; - using lhs = Eval>; - using rhs = Eval>; + using lhs = tav::Car; + using rhs = tav::Cdr; public: - typedef Eval>, - Eval>, + tav::List, Eval> - >> - >> type; + > + >; }; template class Comparator> @@ -42,4 +44,12 @@ struct Sort { } +template < + template class Comparator, + typename Sequence +> +using Sort = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_SORT_H_ diff --git a/src/list/operation/higher/take_while.h b/src/list/operation/higher/take_while.h index 8e61c45..dec5551 100644 --- a/src/list/operation/higher/take_while.h +++ b/src/list/operation/higher/take_while.h @@ -5,19 +5,21 @@ namespace tav { +namespace detail { + template < template class Predicate, typename Current > struct TakeWhile { - typedef Eval>>, - Eval, Eval>> - >>, + >, void - >> type; + > type; }; template < @@ -29,4 +31,12 @@ struct TakeWhile { } +template < + template class Predicate, + typename Current +> +using TakeWhile = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_HIGHER_TAKE_WHILE_H_ diff --git a/src/list/operation/nth.h b/src/list/operation/nth.h index 08e60cc..5a604f4 100644 --- a/src/list/operation/nth.h +++ b/src/list/operation/nth.h @@ -5,20 +5,22 @@ namespace tav { +namespace detail { + template < typename Index, - typename Pair + typename List > struct Nth { typedef Eval>, - Tail + Tail >> type; }; -template -struct Nth, Pair> { - typedef Head type; +template +struct Nth, List> { + typedef Head type; }; template @@ -31,14 +33,22 @@ struct Nth, void> { typedef void type; }; +} + +template < + typename Index, + typename List +> +using Nth = Eval>; + template -using First = Eval, List>>; +using First = Nth, List>; template -using Second = Eval, List>>; +using Second = Nth, List>; template -using Third = Eval, List>>; +using Third = Nth, List>; } diff --git a/src/list/operation/reverse.h b/src/list/operation/reverse.h index d4b2be9..aabba92 100644 --- a/src/list/operation/reverse.h +++ b/src/list/operation/reverse.h @@ -6,6 +6,8 @@ namespace tav { +namespace detail { + template class Reverse { private: @@ -13,16 +15,21 @@ class Reverse { typename Current, typename Previous > - using reversed_append = Append< + using reversed_append = tav::Append< Previous, - Eval> + tav::List >; public: - typedef Eval> type; + typedef tav::Fold type; }; } +template +using Reverse = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_OPERATION_REVERSE_H_ diff --git a/src/list/operation/take.h b/src/list/operation/take.h index fdff123..effba33 100644 --- a/src/list/operation/take.h +++ b/src/list/operation/take.h @@ -5,18 +5,20 @@ namespace tav { +namespace detail { + template < typename Count, typename Current > struct Take { - typedef Eval, Eval>, Tail >> - >> type; + > type; }; template @@ -34,6 +36,13 @@ struct Take, void> { typedef void type; }; +} + +template < + typename Count, + typename Current +> +using Take = Eval>; } -- cgit v1.2.3