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/conditional/cond.h | 19 +++++++++++++------ src/conditional/if.h | 4 ++-- src/function/apply.h | 8 ++++---- src/function/detail/apply.h | 8 ++++---- src/list/cons.h | 26 +++++++++++++++++--------- src/list/generator/iota.h | 17 ++++++++++++++--- src/list/generator/make_list.h | 16 +++++++++++++--- src/list/list.h | 11 +++++++++-- 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 +++++++++++-- src/pair.h | 2 +- src/runtime/list/for_each.h | 2 ++ 27 files changed, 283 insertions(+), 100 deletions(-) create mode 100644 src/list/operation/higher/remove.h (limited to 'src') diff --git a/src/conditional/cond.h b/src/conditional/cond.h index 2d6a415..f6b7965 100644 --- a/src/conditional/cond.h +++ b/src/conditional/cond.h @@ -8,22 +8,29 @@ namespace tav { +namespace detail { + template class Cond { private: template - using predicate = IsTrue>>>; + using predicate = IsTrue>; public: - typedef Eval> - >> - >> type; + tav::List + > + > type; }; } +template +using Cond = Eval>; + +} + #endif // TYPEASVALUE_SRC_CONDITIONAL_COND_H_ diff --git a/src/conditional/if.h b/src/conditional/if.h index b99f399..9be1a50 100644 --- a/src/conditional/if.h +++ b/src/conditional/if.h @@ -10,11 +10,11 @@ template < typename TrueBranch, typename FalseBranch > -using If = std::conditional< +using If = Eval; +>>; } diff --git a/src/function/apply.h b/src/function/apply.h index f4de292..591fa8a 100644 --- a/src/function/apply.h +++ b/src/function/apply.h @@ -19,22 +19,22 @@ template < > struct Apply : Cond< Pair< - GreaterThan>, Size<2>>, + GreaterThan, Size<2>>, detail::apply_variadic >, Pair< - IsEqualValue>, Size<2>>, + IsEqualValue, Size<2>>, detail::apply_pair >, Pair< - IsEqualValue>, Size<1>>, + IsEqualValue, Size<1>>, detail::apply_single >, Pair< Boolean, detail::apply_none > ->::type { }; +> { }; } diff --git a/src/function/detail/apply.h b/src/function/detail/apply.h index da347f7..8d4ef6d 100644 --- a/src/function/detail/apply.h +++ b/src/function/detail/apply.h @@ -13,7 +13,7 @@ namespace detail { struct placeholder_tag { }; template -using is_placeholder = tav::Boolean< +using is_placeholder = Boolean< std::is_base_of::value >; @@ -33,13 +33,13 @@ template < int Index > struct resolve_placeholder> { - typedef Eval, Partials>> type; + typedef tav::Nth, Partials> type; }; template using count_placeholders = Count< is_placeholder, - Eval> + tav::List >; template < @@ -58,7 +58,7 @@ struct apply_variadic { template using function = Function< Eval>, + tav::List, Arguments >>... >; diff --git a/src/list/cons.h b/src/list/cons.h index 8efca67..95783b2 100644 --- a/src/list/cons.h +++ b/src/list/cons.h @@ -5,18 +5,12 @@ namespace tav { -template < - typename CAR, - typename CDR -> -struct Cons { - typedef Pair type; -}; +namespace detail { template struct Car { static_assert( - Eval>::value, + IsPair::value, "Pair type required" ); @@ -26,7 +20,7 @@ struct Car { template struct Cdr { static_assert( - Eval>::value, + IsPair::value, "Pair type required" ); @@ -35,4 +29,18 @@ struct Cdr { } +template < + typename CAR, + typename CDR +> +using Cons = Pair; + +template +using Car = Eval>; + +template +using Cdr = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_CONS_H_ diff --git a/src/list/generator/iota.h b/src/list/generator/iota.h index 56ebeca..73b7cc8 100644 --- a/src/list/generator/iota.h +++ b/src/list/generator/iota.h @@ -5,20 +5,22 @@ namespace tav { +namespace detail { + template < typename Count, typename Initial, typename Step > struct Iota { - typedef Eval>, Add, Step >> - >> type; + > type; }; template < @@ -26,9 +28,18 @@ template < typename Step > struct Iota, Initial, Step> { - typedef Eval> type; + typedef Cons type; }; } +template < + typename Count, + typename Initial, + typename Step +> +using Iota = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_GENERATOR_IOTA_H_ diff --git a/src/list/generator/make_list.h b/src/list/generator/make_list.h index d927905..863dce2 100644 --- a/src/list/generator/make_list.h +++ b/src/list/generator/make_list.h @@ -6,25 +6,35 @@ namespace tav { +namespace detail { + template < typename Count, typename Element > struct MakeList { - typedef Eval>, Element >> - >> type; + > type; }; template struct MakeList, Element> { - typedef Eval> type; + typedef Cons type; }; } +template < + typename Count, + typename Element +> +using MakeList = Eval>; + +} + #endif // TYPEASVALUE_SRC_LIST_GENERATOR_MAKE_LIST_H_ diff --git a/src/list/list.h b/src/list/list.h index e369739..c9e6a9e 100644 --- a/src/list/list.h +++ b/src/list/list.h @@ -5,6 +5,8 @@ namespace tav { +namespace detail { + template < typename Head, typename... Tail @@ -36,6 +38,11 @@ struct List { typedef void type; }; +} + +template +using List = Eval>; + template < typename Type, Type... Values @@ -45,10 +52,10 @@ using ListOfType = List< >; template -using Head = Eval>; +using Head = Car; template -using Tail = Eval>; +using Tail = Cdr; } 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>; } diff --git a/src/pair.h b/src/pair.h index 20bef4e..8234382 100644 --- a/src/pair.h +++ b/src/pair.h @@ -19,7 +19,7 @@ struct Pair : detail::pair_tag { }; template -using IsPair = std::is_base_of; +using IsPair = Eval>; } diff --git a/src/runtime/list/for_each.h b/src/runtime/list/for_each.h index b7496a8..a7dc2a8 100644 --- a/src/runtime/list/for_each.h +++ b/src/runtime/list/for_each.h @@ -7,6 +7,7 @@ #include "list/list.h" namespace tav { + namespace runtime { template < @@ -28,6 +29,7 @@ void for_each(const Function& function) { } } + } #endif // TYPEASVALUE_SRC_RUNTIME_LIST_FOR_EACH_H_ -- cgit v1.2.3