From a59df7e8c4fd1f88bc1078ebcfde944502b0c309 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 15 Feb 2015 22:37:06 +0100 Subject: Simplified `Cond`, `Cons` and `Map` implementations * continuation of 8e49cc6f8f --- src/conditional/cond.h | 24 ++++++++---------------- src/list/cons.h | 28 ++-------------------------- src/list/operation/higher/map.h | 34 +++++++++++++++------------------- 3 files changed, 25 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/conditional/cond.h b/src/conditional/cond.h index f6b7965..eeb31b6 100644 --- a/src/conditional/cond.h +++ b/src/conditional/cond.h @@ -10,26 +10,18 @@ namespace tav { namespace detail { -template -class Cond { - private: - template - using predicate = IsTrue>; - - public: - typedef tav::Cdr< - tav::Find< - predicate, - tav::List - > - > type; - -}; +template +using cond_predicate = IsTrue>; } template -using Cond = Eval>; +using Cond = Cdr< + Find< + detail::cond_predicate, + List + > +>; } diff --git a/src/list/cons.h b/src/list/cons.h index 95783b2..dbd4c0b 100644 --- a/src/list/cons.h +++ b/src/list/cons.h @@ -5,30 +5,6 @@ namespace tav { -namespace detail { - -template -struct Car { - static_assert( - IsPair::value, - "Pair type required" - ); - - typedef typename Pair::car type; -}; - -template -struct Cdr { - static_assert( - IsPair::value, - "Pair type required" - ); - - typedef typename Pair::cdr type; -}; - -} - template < typename CAR, typename CDR @@ -36,10 +12,10 @@ template < using Cons = Pair; template -using Car = Eval>; +using Car = typename Pair::car; template -using Cdr = Eval>; +using Cdr = typename Pair::cdr; } diff --git a/src/list/operation/higher/map.h b/src/list/operation/higher/map.h index cc30355..00956a5 100644 --- a/src/list/operation/higher/map.h +++ b/src/list/operation/higher/map.h @@ -7,24 +7,16 @@ namespace tav { namespace detail { -template < - template class Function, - typename List -> -class Map { - private: - template < - typename Current, - typename Previous - > - using function_wrapper = Cons< - Eval>, - Previous - >; - - public: - using type = tav::Fold; - +template class Function> +struct map_transformation { + template < + typename Current, + typename Previous + > + using function = Cons< + Eval>, + Previous + >; }; } @@ -33,7 +25,11 @@ template < template class Function, typename List > -using Map = Eval>; +using Map = Fold< + detail::map_transformation::template function, + void, + List +>; } -- cgit v1.2.3