diff options
Diffstat (limited to 'src')
27 files changed, 283 insertions, 100 deletions
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 <typename... Branches> class Cond { private: template <typename Pair> - using predicate = IsTrue<Eval<Eval<Car<Pair>>>>; + using predicate = IsTrue<tav::Car<Pair>>; public: - typedef Eval<Cdr< - Eval<Find< + typedef tav::Cdr< + tav::Find< predicate, - Eval<List<Branches...>> - >> - >> type; + tav::List<Branches...> + > + > type; }; } +template <typename... Branches> +using Cond = Eval<detail::Cond<Branches...>>; + +} + #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<std::conditional< Condition::value, TrueBranch, FalseBranch ->; +>>; } 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<Eval<detail::count_placeholders<Arguments...>>, Size<2>>, + GreaterThan<detail::count_placeholders<Arguments...>, Size<2>>, detail::apply_variadic<Function, Arguments...> >, Pair< - IsEqualValue<Eval<detail::count_placeholders<Arguments...>>, Size<2>>, + IsEqualValue<detail::count_placeholders<Arguments...>, Size<2>>, detail::apply_pair<Function, Arguments...> >, Pair< - IsEqualValue<Eval<detail::count_placeholders<Arguments...>>, Size<1>>, + IsEqualValue<detail::count_placeholders<Arguments...>, Size<1>>, detail::apply_single<Function, Arguments...> >, Pair< Boolean<true>, detail::apply_none<Function, Arguments...> > ->::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 <typename Type> -using is_placeholder = tav::Boolean< +using is_placeholder = Boolean< std::is_base_of<placeholder_tag, Type>::value >; @@ -33,13 +33,13 @@ template < int Index > struct resolve_placeholder<Partials, placeholder<Index>> { - typedef Eval<Nth<Size<Index>, Partials>> type; + typedef tav::Nth<Size<Index>, Partials> type; }; template <typename... Arguments> using count_placeholders = Count< is_placeholder, - Eval<List<Arguments...>> + tav::List<Arguments...> >; template < @@ -58,7 +58,7 @@ struct apply_variadic { template <typename... Partials> using function = Function< Eval<resolve_placeholder< - Eval<List<Partials...>>, + tav::List<Partials...>, 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<CAR, CDR> type; -}; +namespace detail { template <typename Pair> struct Car { static_assert( - Eval<IsPair<Pair>>::value, + IsPair<Pair>::value, "Pair type required" ); @@ -26,7 +20,7 @@ struct Car { template <typename Pair> struct Cdr { static_assert( - Eval<IsPair<Pair>>::value, + IsPair<Pair>::value, "Pair type required" ); @@ -35,4 +29,18 @@ struct Cdr { } +template < + typename CAR, + typename CDR +> +using Cons = Pair<CAR, CDR>; + +template <typename Pair> +using Car = Eval<detail::Car<Pair>>; + +template <typename Pair> +using Cdr = Eval<detail::Cdr<Pair>>; + +} + #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<Cons< + typedef Cons< Initial, Eval<Iota< Substract<Count, Size<1>>, Add<Initial, Step>, Step >> - >> type; + > type; }; template < @@ -26,9 +28,18 @@ template < typename Step > struct Iota<Size<1>, Initial, Step> { - typedef Eval<Cons<Initial, void>> type; + typedef Cons<Initial, void> type; }; } +template < + typename Count, + typename Initial, + typename Step +> +using Iota = Eval<detail::Iota<Count, Initial, Step>>; + +} + #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<Cons< + typedef Cons< Element, Eval<MakeList< Substract<Count, Size<1>>, Element >> - >> type; + > type; }; template <typename Element> struct MakeList<Size<1>, Element> { - typedef Eval<Cons<Element, void>> type; + typedef Cons<Element, void> type; }; } +template < + typename Count, + typename Element +> +using MakeList = Eval<detail::MakeList<Count, Element>>; + +} + #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<void, void> { typedef void type; }; +} + +template <typename... Elements> +using List = Eval<detail::List<Elements...>>; + template < typename Type, Type... Values @@ -45,10 +52,10 @@ using ListOfType = List< >; template <typename Cons> -using Head = Eval<Car<Cons>>; +using Head = Car<Cons>; template <typename Cons> -using Tail = Eval<Cdr<Cons>>; +using Tail = Cdr<Cons>; } 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<Cons< + typedef Cons< Head<Primary>, Eval<Append< Tail<Primary>, Secondary >> - >> type; + > type; }; template <typename Secondary> @@ -24,4 +26,12 @@ struct Append<void, Secondary> { } +template < + typename Primary, + typename Secondary +> +using Append = Eval<detail::Append<Primary, Secondary>>; + +} + #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 <typename Cons> +namespace detail { + +template <typename List> class Length { private: template <typename, typename Accumulated> using accumulate = Add<Size<1>, Accumulated>; public: - typedef Eval<Fold< - accumulate, - Size<0>, - Cons - >> type; + typedef tav::Fold<accumulate, Size<0>, List> type; }; } +template <typename List> +using Length = Eval<detail::Length<List>>; + +} + #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<Take<Index, List>>, - Eval<Drop<Add<Index, Size<1>>, List>> + Take<Index, List>, + Drop<Add<Index, Size<1>>, 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<Size<0>, void> { typedef void type; }; +} + +template < + typename Count, + typename Current +> +using Drop = Eval<detail::Drop<Count, Current>>; } 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<typename> class Predicate, typename Current > struct DropWhile { - typedef Eval<If< + typedef If< Eval<Predicate<Head<Current>>>, Eval<DropWhile<Predicate, Tail<Current>>>, Current - >> type; + > type; }; template < @@ -26,4 +28,12 @@ struct DropWhile<Predicate, void> { } +template < + template<typename> class Predicate, + typename Current +> +using DropWhile = Eval<detail::DropWhile<Predicate, Current>>; + +} + #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<typename> class Predicate, typename List @@ -18,28 +20,22 @@ class Filter { > using predicate_wrapper = If< Eval<Predicate<Current>>, - Eval<Cons<Current, Previous>>, + Cons<Current, Previous>, Previous >; public: - typedef Eval<Fold<predicate_wrapper, void, List>> type; + typedef tav::Fold<predicate_wrapper, void, List> type; }; +} + template < template<typename> class Predicate, typename List > -class Remove { - private: - template <typename Element> - using predicate_negator = Not<Predicate<Element>>; - - public: - typedef Eval<Filter<predicate_negator, List>> type; - -}; +using Filter = Eval<detail::Filter<Predicate, List>>; } 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<typename> class Predicate, typename Current > struct Find { - typedef Eval<If< + typedef If< Eval<Predicate<Head<Current>>>, Head<Current>, Eval<Find<Predicate, Tail<Current>>> - >> type; + > type; }; template < @@ -27,4 +29,12 @@ struct Find<Predicate, void> { } +template < + template<typename> class Predicate, + typename List +> +using Find = Eval<detail::Find<Predicate, List>>; + +} + #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<typename, typename> class Function, typename Initial, typename Current > struct Fold { - typedef Eval<Function< + typedef Function< Head<Current>, Eval<Fold<Function, Initial, Tail<Current>>> - >> type; + > type; }; template < @@ -25,4 +27,13 @@ struct Fold<Function, Initial, void> { } +template < + template<typename, typename> class Function, + typename Initial, + typename Current +> +using Fold = Eval<detail::Fold<Function, Initial, Current>>; + +} + #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<typename> class Function, typename List @@ -21,10 +23,18 @@ class Map { >; public: - typedef Eval<Fold<function_wrapper, void, List>> type; + using type = tav::Fold<function_wrapper, void, List>; }; } +template < + template<typename> class Function, + typename List +> +using Map = Eval<detail::Map<Function, List>>; + +} + #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<Filter<Predicate, Elements>>, - Eval<Remove<Predicate, Elements>> + Filter<Predicate, Elements>, + Remove<Predicate, Elements> >; } 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<false>, - Eval<Map<Predicate, List>> + Map<Predicate, List> >; template < @@ -25,16 +25,14 @@ template < using All = Fold< And, Boolean<true>, - Eval<Map<Predicate, List>> + Map<Predicate, List> >; template < template<typename> class Predicate, typename List > -using None = Not< - Eval<Any<Predicate, List>> ->; +using None = Not<Any<Predicate, List>>; template < template<typename> class Predicate, @@ -42,8 +40,8 @@ template < > using Count = Fold< Add, - tav::Size<0>, - Eval<Map<Predicate, List>> + Size<0>, + Map<Predicate, List> >; } 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<typename> class Predicate, + typename List +> +class Remove { + private: + template <typename Element> + using predicate_negator = Not<Predicate<Element>>; + + public: + typedef tav::Filter<predicate_negator, List> type; + +}; + +} + +template < + template<typename> class Predicate, + typename List +> +using Remove = Eval<detail::Remove<Predicate, List>>; + +} + +#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<typename, typename> class Comparator, typename Sequence > class Sort { private: - using index = Divide<Eval<Length<Sequence>>, Size<2>>; - using pivot = Eval<Nth<index, Sequence>>; + using index = Divide<tav::Length<Sequence>, Size<2>>; + using pivot = tav::Nth<index, Sequence>; - using partitions = Eval<Partition< + using partitions = Partition< Apply<Comparator, pivot, _0>::template function, - Eval<DeleteNth<index, Sequence>> - >>; + DeleteNth<index, Sequence> + >; - using lhs = Eval<Car<partitions>>; - using rhs = Eval<Cdr<partitions>>; + using lhs = tav::Car<partitions>; + using rhs = tav::Cdr<partitions>; public: - typedef Eval<Concatenate< - Eval<List< + using type = Concatenate< + tav::List< Eval<Sort<Comparator, lhs>>, - Eval<List<pivot>>, + tav::List<pivot>, Eval<Sort<Comparator, rhs>> - >> - >> type; + > + >; }; template <template<typename, typename> class Comparator> @@ -42,4 +44,12 @@ struct Sort<Comparator, void> { } +template < + template<typename, typename> class Comparator, + typename Sequence +> +using Sort = Eval<detail::Sort<Comparator, Sequence>>; + +} + #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<typename> class Predicate, typename Current > struct TakeWhile { - typedef Eval<If< + typedef If< Eval<Predicate<Head<Current>>>, - Eval<Cons< + Cons< Head<Current>, Eval<TakeWhile<Predicate, Tail<Current>>> - >>, + >, void - >> type; + > type; }; template < @@ -29,4 +31,12 @@ struct TakeWhile<Predicate, void> { } +template < + template<typename> class Predicate, + typename Current +> +using TakeWhile = Eval<detail::TakeWhile<Predicate, Current>>; + +} + #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<Nth< Substract<Index, Size<1>>, - Tail<Pair> + Tail<List> >> type; }; -template <typename Pair> -struct Nth<Size<0>, Pair> { - typedef Head<Pair> type; +template <typename List> +struct Nth<Size<0>, List> { + typedef Head<List> type; }; template <typename Index> @@ -31,14 +33,22 @@ struct Nth<Size<0>, void> { typedef void type; }; +} + +template < + typename Index, + typename List +> +using Nth = Eval<detail::Nth<Index, List>>; + template <typename List> -using First = Eval<Nth<Size<0>, List>>; +using First = Nth<Size<0>, List>; template <typename List> -using Second = Eval<Nth<Size<1>, List>>; +using Second = Nth<Size<1>, List>; template <typename List> -using Third = Eval<Nth<Size<2>, List>>; +using Third = Nth<Size<2>, 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 <typename Sequence> class Reverse { private: @@ -13,16 +15,21 @@ class Reverse { typename Current, typename Previous > - using reversed_append = Append< + using reversed_append = tav::Append< Previous, - Eval<List<Current>> + tav::List<Current> >; public: - typedef Eval<Fold<reversed_append, void, Sequence>> type; + typedef tav::Fold<reversed_append, void, Sequence> type; }; } +template <typename Sequence> +using Reverse = Eval<detail::Reverse<Sequence>>; + +} + #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<Cons< + typedef Cons< Head<Current>, Eval<Take< Substract<Count, Size<1>>, Tail<Current> >> - >> type; + > type; }; template <typename Current> @@ -34,6 +36,13 @@ struct Take<Size<0>, void> { typedef void type; }; +} + +template < + typename Count, + typename Current +> +using Take = Eval<detail::Take<Count, Current>>; } @@ -19,7 +19,7 @@ struct Pair : detail::pair_tag { }; template <typename Type> -using IsPair = std::is_base_of<detail::pair_tag, Type>; +using IsPair = Eval<std::is_base_of<detail::pair_tag, Type>>; } 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_ |