From f4ca222dbd47ac457db068f8e9351677f53e5bd0 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 7 Jun 2015 16:32:32 +0100 Subject: [PATCH] remove duplicate code + further simplify --- octa/algorithm.h | 101 ++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 76 deletions(-) diff --git a/octa/algorithm.h b/octa/algorithm.h index 580e4f7..392efbd 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -414,59 +414,58 @@ T foldr(R range, T init, F func) { namespace detail { template - struct MapLambdaTypes: MapLambdaTypes {}; + struct HofLambdaTypes: HofLambdaTypes {}; template - struct MapLambdaTypes { + struct HofLambdaTypes { typedef R Result; typedef A Arg; }; template - using MapLambdaRet = typename MapLambdaTypes::Result; + using HofLambdaRet = typename HofLambdaTypes::Result; template - using MapLambdaArg = typename MapLambdaTypes::Arg; + using HofLambdaArg = typename HofLambdaTypes::Arg; template - struct MapFuncTest { + struct HofFuncTest { template - static char test(MapLambdaRet (*)(MapLambdaArg)); + static char test(HofLambdaRet (*)(HofLambdaArg)); template static int test(...); static constexpr bool value = (sizeof(test(octa::declval())) == 1); }; - template::value> - struct MapFuncTypeObjBase { - typedef octa::Function)> Type; + template::value> + struct HofFuncTypeObjBase { + typedef octa::Function(HofLambdaArg)> Type; }; - template - struct MapFuncTypeObjBase { - typedef MapLambdaRet (*Type)(MapLambdaArg); + template + struct HofFuncTypeObjBase { + typedef HofLambdaRet (*Type)(HofLambdaArg); }; - template::value && - octa::IsMoveConstructible::value - > struct MapFuncTypeObj { - typedef typename MapFuncTypeObjBase::Type Type; + template::value && + octa::IsMoveConstructible::value + > struct HofFuncTypeObj { + typedef typename HofFuncTypeObjBase::Type Type; }; - template - struct MapFuncTypeObj { + template + struct HofFuncTypeObj { typedef F Type; }; - template::value> - struct MapFuncType { + template::value> + struct HofFuncType { typedef F Type; }; - template - struct MapFuncType { - typedef typename MapFuncTypeObj::Type Type; + template + struct HofFuncType { + typedef typename HofFuncTypeObj::Type Type; }; } @@ -476,7 +475,7 @@ struct MapRange: InputRange< > { private: T p_range; - typename octa::detail::MapFuncType::Type p_func; + typename octa::detail::HofFuncType::Type p_func; public: MapRange(): p_range(), p_func() {} @@ -560,56 +559,6 @@ MapRange> map(R range, func); } -namespace detail { - template - struct FilterLambdaArg: FilterLambdaArg {}; - - template - struct FilterLambdaArg { - typedef A Type; - }; - - template - struct FilterPredTest { - template - static char test(bool (*)(typename FilterLambdaArg::Type)); - template - static int test(...); - static constexpr bool value = (sizeof(test(octa::declval())) == 1); - }; - - template::value> - struct FilterPredTypeObjBase { - typedef octa::Function::Type)> Type; - }; - - template - struct FilterPredTypeObjBase { - typedef bool (*Type)(typename FilterLambdaArg::Type); - }; - - template::value && - octa::IsMoveConstructible::value - > struct FilterPredTypeObj { - typedef typename FilterPredTypeObjBase::Type Type; - }; - - template - struct FilterPredTypeObj { - typedef F Type; - }; - - template::value> - struct FilterPredType { - typedef F Type; - }; - - template - struct FilterPredType { - typedef typename FilterPredTypeObj::Type Type; - }; -} - template struct FilterRange: InputRange< FilterRange, octa::CommonType, @@ -618,7 +567,7 @@ struct FilterRange: InputRange< > { private: T p_range; - typename octa::detail::FilterPredType::Type p_pred; + typename octa::detail::HofFuncType::Type p_pred; void advance_valid() { while (!p_range.empty() && !p_pred(front())) p_range.pop_front();