From 78e954aa5864aed6d3c60d94813fec87f92aaa08 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 11 Apr 2015 12:19:12 +0900 Subject: [PATCH] reimplementation types::fold --- sprout/type/algorithm/fold.hpp | 43 +++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/sprout/type/algorithm/fold.hpp b/sprout/type/algorithm/fold.hpp index 273d37a7..419adc1a 100644 --- a/sprout/type/algorithm/fold.hpp +++ b/sprout/type/algorithm/fold.hpp @@ -8,7 +8,6 @@ #ifndef SPROUT_TYPE_ALGORITHM_FOLD_HPP #define SPROUT_TYPE_ALGORITHM_FOLD_HPP -#include #include #include #include @@ -18,30 +17,52 @@ namespace sprout { namespace types { namespace detail { template< - typename Tuple, typename T, typename BinaryOp, std::size_t I, - bool Valid = (I != sprout::types::tuple_size::value) + typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last, + std::size_t Pivot, + bool C0 = (Pivot == 0) > struct fold_impl; - template - struct fold_impl - : public sprout::identity + template< + typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last, + std::size_t Pivot + > + struct fold_impl + : public sprout::types::apply::type> {}; - template - struct fold_impl + template< + typename Tuple, typename T, typename BinaryOp, std::size_t First, std::size_t Last, + std::size_t Pivot + > + struct fold_impl : public sprout::types::detail::fold_impl< Tuple, - typename sprout::types::apply::type>::type, + typename sprout::types::detail::fold_impl< + Tuple, + T, + BinaryOp, + First, First + Pivot, + Pivot / 2 + >::type, BinaryOp, - I + 1 + First + Pivot, Last, + (Last - First - Pivot) / 2 > {}; + template::value> + struct fold + : public sprout::types::detail::fold_impl + {}; + template + struct fold + : public sprout::identity + {}; } // namespace detail // // fold // template struct fold - : public sprout::types::detail::fold_impl + : public sprout::types::detail::fold {}; #if SPROUT_USE_TEMPLATE_ALIASES