diff --git a/include/boost/fusion/algorithm/iteration/detail/preprocessed/fold.hpp b/include/boost/fusion/algorithm/iteration/detail/preprocessed/fold.hpp index bd3b1dbd..eb5bc9ab 100644 --- a/include/boost/fusion/algorithm/iteration/detail/preprocessed/fold.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/preprocessed/fold.hpp @@ -12,341 +12,110 @@ namespace boost { namespace fusion { namespace detail { - template - struct fold_lvalue_state - : fusion::detail::result_of_with_decltype< - F( - typename add_reference::type>::type, - typename fusion::result_of::deref::type) - > + template + struct result_of_it_fold {}; - template - struct unrolled_fold + template + struct result_of_it_fold<0,It,State,F + , typename boost::enable_if_has_type::type> { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_3(State3 const& state3,It3 const& it3,F& f) - { - return unrolled_fold< - Result - , N-4 - >::call( - f(state3,fusion::deref(it3)), - fusion::next(it3), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return call_3( - f(state2,fusion::deref(it2)), - fusion::next(it2), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,fusion::deref(it1)), - fusion::next(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::next(it0), - f); - } + typedef typename State::type type; }; - template - struct unrolled_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return f(state2,fusion::deref(it2)); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,fusion::deref(it1)), - fusion::next(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::next(it0), - f); - } - }; - template - struct unrolled_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return f(state1,fusion::deref(it1)); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::next(it0), - f); - } - }; - template - struct unrolled_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return f(state, - fusion::deref(it0)); - } - }; - template - struct unrolled_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const&, F) - { - return static_cast(state); - } - }; - template - struct result_of_unrolled_fold - { - typedef typename - fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::next< - It0 const - >::type - it1; - typedef typename - fold_lvalue_state< - rest1 - , it1 - , F - >::type - rest2; - typedef typename - result_of::next::type - it2; - typedef typename - fold_lvalue_state< - rest2 - , it2 - , F - >::type - rest3; - typedef typename - result_of::next::type - it3; - typedef typename - result_of_unrolled_fold< - typename fold_lvalue_state< - rest3 - , it3 - , F - >::type - , typename result_of::next< - it3 - >::type - , F - , N-4 - >::type - type; - }; - template - struct result_of_unrolled_fold< - StateRef - , It0 - , F - , 3 - > - { - typedef typename - fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::next< - It0 const - >::type - it1; - typedef typename - fold_lvalue_state< - typename fold_lvalue_state< - rest1 - , it1 - , F - >::type - , typename result_of::next< - it1 const - >::type const - , F - >::type - type; - }; - template - struct result_of_unrolled_fold< - StateRef - , It0 - , F - , 2 - > - : fold_lvalue_state< - typename fold_lvalue_state< - StateRef - , It0 const - , F - >::type - , typename result_of::next< - It0 const - >::type const + template + struct result_of_it_fold::type::type + >::type> + : result_of_it_fold< + SeqSize-1 + , typename result_of::next::type + , boost::result_of< + F( + typename add_reference::type, + typename fusion::result_of::deref::type + ) + > , F > {}; - template - struct result_of_unrolled_fold< - StateRef - , It0 + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_it_fold< + 0 + , It + , State , F - , 1 - > - : fold_lvalue_state< - StateRef - , It0 const + >::type + it_fold(mpl::int_<0>, It const&, typename State::type state, F&) + { + return state; + } + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename lazy_enable_if_c< + SeqSize != 0 + , result_of_it_fold< + SeqSize + , It + , State , F > - {}; - template - struct result_of_unrolled_fold< - StateRef - , It0 - , F - , 0 - > + >::type + it_fold(mpl::int_, It const& it, typename State::type state, F& f) { - typedef StateRef type; - }; - template - struct result_of_first_unrolledfold - { - typedef typename - result_of_unrolled_fold< - typename fusion::detail::result_of_with_decltype< - F( - StateRef, - typename fusion::result_of::deref< It0 const>::type - ) - >::type - , typename result_of::next< - It0 const - >::type - , F - , SeqSize-1 - >::type - type; - }; - template - struct fold_impl - { - typedef typename - result_of_first_unrolledfold< - StateRef - , typename result_of::begin::type - , F - , SeqSize - >::type - type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static type - call(StateRef state, Seq& seq, F f) - { - typedef - unrolled_fold< - type - , SeqSize - > - unrolled_impl; - return unrolled_impl::call( - state, - fusion::begin(seq), - f); - } - }; - template - struct fold_impl<0,StateRef,Seq,F> - { - typedef StateRef type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static StateRef - call(StateRef state, Seq&, F) - { - return static_cast(state); - } - }; - template + return it_fold< + typename result_of::next::type + , boost::result_of< + F( + typename add_reference::type, + typename fusion::result_of::deref::type + ) + > + , F + >( + mpl::int_() + , fusion::next(it) + , f(state, fusion::deref(it)) + , f + ); + } + template::value + , bool = traits::is_segmented::value> struct result_of_fold - : fold_impl< + {}; + template + struct result_of_fold + : result_of_it_fold< result_of::size::value - , typename add_reference< - typename add_const::type - >::type - , Seq + , typename result_of::begin::type + , add_reference , F > {}; + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_fold::type + fold(Seq& seq, State& state, F& f) + { + return it_fold< + typename result_of::begin::type + , add_reference + , F + >( + typename result_of::size::type() + , fusion::begin(seq) + , state + , f + ); + } } namespace result_of { template struct fold - : detail::result_of_fold< - Seq - , State - , F - , traits::is_segmented::type::value - > + : detail::result_of_fold {}; } template @@ -358,10 +127,7 @@ namespace boost { namespace fusion >::type fold(Seq& seq, State const& state, F f) { - return result_of::fold::call( - state, - seq, - f); + return detail::fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED @@ -372,37 +138,28 @@ namespace boost { namespace fusion >::type fold(Seq const& seq, State const& state, F f) { - return result_of::fold::call( - state, - seq, - f); + return detail::fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::fold< Seq - , State const + , State , F >::type fold(Seq& seq, State& state, F f) { - return result_of::fold::call( - state, - seq, - f); + return detail::fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::fold< Seq const - , State const + , State , F >::type fold(Seq const& seq, State& state, F f) { - return result_of::fold::call( - state, - seq, - f); + return detail::fold(seq, state, f); } }} diff --git a/include/boost/fusion/algorithm/iteration/detail/preprocessed/iter_fold.hpp b/include/boost/fusion/algorithm/iteration/detail/preprocessed/iter_fold.hpp index 1d294a87..3895526c 100644 --- a/include/boost/fusion/algorithm/iteration/detail/preprocessed/iter_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/preprocessed/iter_fold.hpp @@ -11,341 +11,110 @@ namespace boost { namespace fusion { namespace detail { - template - struct iter_fold_lvalue_state - : fusion::detail::result_of_with_decltype< - F( - typename add_reference::type>::type, - It&) - > + template + struct result_of_it_iter_fold {}; - template - struct unrolled_iter_fold + template + struct result_of_it_iter_fold<0,It,State,F + , typename boost::enable_if_has_type::type> { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_3(State3 const& state3,It3 const& it3,F& f) - { - return unrolled_iter_fold< - Result - , N-4 - >::call( - f(state3,it3), - fusion::next(it3), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return call_3( - f(state2,it2), - fusion::next(it2), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,it1), - fusion::next(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::next(it0), - f); - } + typedef typename State::type type; }; - template - struct unrolled_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return f(state2,it2); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,it1), - fusion::next(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::next(it0), - f); - } - }; - template - struct unrolled_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return f(state1,it1); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::next(it0), - f); - } - }; - template - struct unrolled_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return f(state, - it0); - } - }; - template - struct unrolled_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const&, F) - { - return static_cast(state); - } - }; - template - struct result_of_unrolled_iter_fold - { - typedef typename - iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::next< - It0 const - >::type - it1; - typedef typename - iter_fold_lvalue_state< - rest1 - , it1 - , F - >::type - rest2; - typedef typename - result_of::next::type - it2; - typedef typename - iter_fold_lvalue_state< - rest2 - , it2 - , F - >::type - rest3; - typedef typename - result_of::next::type - it3; - typedef typename - result_of_unrolled_iter_fold< - typename iter_fold_lvalue_state< - rest3 - , it3 - , F - >::type - , typename result_of::next< - it3 - >::type - , F - , N-4 - >::type - type; - }; - template - struct result_of_unrolled_iter_fold< - StateRef - , It0 - , F - , 3 - > - { - typedef typename - iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::next< - It0 const - >::type - it1; - typedef typename - iter_fold_lvalue_state< - typename iter_fold_lvalue_state< - rest1 - , it1 - , F - >::type - , typename result_of::next< - it1 const - >::type const - , F - >::type - type; - }; - template - struct result_of_unrolled_iter_fold< - StateRef - , It0 - , F - , 2 - > - : iter_fold_lvalue_state< - typename iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - , typename result_of::next< - It0 const - >::type const + template + struct result_of_it_iter_fold::type::type + >::type> + : result_of_it_iter_fold< + SeqSize-1 + , typename result_of::next::type + , boost::result_of< + F( + typename add_reference::type, + It const& + ) + > , F > {}; - template - struct result_of_unrolled_iter_fold< - StateRef - , It0 + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_it_iter_fold< + 0 + , It + , State , F - , 1 - > - : iter_fold_lvalue_state< - StateRef - , It0 const + >::type + it_iter_fold(mpl::int_<0>, It const&, typename State::type state, F&) + { + return state; + } + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename lazy_enable_if_c< + SeqSize != 0 + , result_of_it_iter_fold< + SeqSize + , It + , State , F > - {}; - template - struct result_of_unrolled_iter_fold< - StateRef - , It0 - , F - , 0 - > + >::type + it_iter_fold(mpl::int_, It const& it, typename State::type state, F& f) { - typedef StateRef type; - }; - template - struct result_of_first_unrollediter_fold - { - typedef typename - result_of_unrolled_iter_fold< - typename fusion::detail::result_of_with_decltype< - F( - StateRef, - It0 const& - ) - >::type - , typename result_of::next< - It0 const - >::type - , F - , SeqSize-1 - >::type - type; - }; - template - struct iter_fold_impl - { - typedef typename - result_of_first_unrollediter_fold< - StateRef - , typename result_of::begin::type - , F - , SeqSize - >::type - type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static type - call(StateRef state, Seq& seq, F f) - { - typedef - unrolled_iter_fold< - type - , SeqSize - > - unrolled_impl; - return unrolled_impl::call( - state, - fusion::begin(seq), - f); - } - }; - template - struct iter_fold_impl<0,StateRef,Seq,F> - { - typedef StateRef type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static StateRef - call(StateRef state, Seq&, F) - { - return static_cast(state); - } - }; - template + return it_iter_fold< + typename result_of::next::type + , boost::result_of< + F( + typename add_reference::type, + It const& + ) + > + , F + >( + mpl::int_() + , fusion::next(it) + , f(state, it) + , f + ); + } + template::value + , bool = traits::is_segmented::value> struct result_of_iter_fold - : iter_fold_impl< + {}; + template + struct result_of_iter_fold + : result_of_it_iter_fold< result_of::size::value - , typename add_reference< - typename add_const::type - >::type - , Seq + , typename result_of::begin::type + , add_reference , F > {}; + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_iter_fold::type + iter_fold(Seq& seq, State& state, F& f) + { + return it_iter_fold< + typename result_of::begin::type + , add_reference + , F + >( + typename result_of::size::type() + , fusion::begin(seq) + , state + , f + ); + } } namespace result_of { template struct iter_fold - : detail::result_of_iter_fold< - Seq - , State - , F - , traits::is_segmented::type::value - > + : detail::result_of_iter_fold {}; } template @@ -357,10 +126,7 @@ namespace boost { namespace fusion >::type iter_fold(Seq& seq, State const& state, F f) { - return result_of::iter_fold::call( - state, - seq, - f); + return detail::iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED @@ -371,37 +137,28 @@ namespace boost { namespace fusion >::type iter_fold(Seq const& seq, State const& state, F f) { - return result_of::iter_fold::call( - state, - seq, - f); + return detail::iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::iter_fold< Seq - , State const + , State , F >::type iter_fold(Seq& seq, State& state, F f) { - return result_of::iter_fold::call( - state, - seq, - f); + return detail::iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::iter_fold< Seq const - , State const + , State , F >::type iter_fold(Seq const& seq, State& state, F f) { - return result_of::iter_fold::call( - state, - seq, - f); + return detail::iter_fold(seq, state, f); } }} diff --git a/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_fold.hpp b/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_fold.hpp index 94789782..a6705b08 100644 --- a/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_fold.hpp @@ -11,341 +11,110 @@ namespace boost { namespace fusion { namespace detail { - template - struct reverse_fold_lvalue_state - : fusion::detail::result_of_with_decltype< - F( - typename add_reference::type>::type, - typename fusion::result_of::deref::type) - > + template + struct result_of_it_reverse_fold {}; - template - struct unrolled_reverse_fold + template + struct result_of_it_reverse_fold<0,It,State,F + , typename boost::enable_if_has_type::type> { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_3(State3 const& state3,It3 const& it3,F& f) - { - return unrolled_reverse_fold< - Result - , N-4 - >::call( - f(state3,fusion::deref(it3)), - fusion::prior(it3), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return call_3( - f(state2,fusion::deref(it2)), - fusion::prior(it2), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,fusion::deref(it1)), - fusion::prior(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::prior(it0), - f); - } + typedef typename State::type type; }; - template - struct unrolled_reverse_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return f(state2,fusion::deref(it2)); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,fusion::deref(it1)), - fusion::prior(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::prior(it0), - f); - } - }; - template - struct unrolled_reverse_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return f(state1,fusion::deref(it1)); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,fusion::deref(it0)), - fusion::prior(it0), - f); - } - }; - template - struct unrolled_reverse_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return f(state, - fusion::deref(it0)); - } - }; - template - struct unrolled_reverse_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const&, F) - { - return static_cast(state); - } - }; - template - struct result_of_unrolled_reverse_fold - { - typedef typename - reverse_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::prior< - It0 const - >::type - it1; - typedef typename - reverse_fold_lvalue_state< - rest1 - , it1 - , F - >::type - rest2; - typedef typename - result_of::prior::type - it2; - typedef typename - reverse_fold_lvalue_state< - rest2 - , it2 - , F - >::type - rest3; - typedef typename - result_of::prior::type - it3; - typedef typename - result_of_unrolled_reverse_fold< - typename reverse_fold_lvalue_state< - rest3 - , it3 - , F - >::type - , typename result_of::prior< - it3 - >::type - , F - , N-4 - >::type - type; - }; - template - struct result_of_unrolled_reverse_fold< - StateRef - , It0 - , F - , 3 - > - { - typedef typename - reverse_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::prior< - It0 const - >::type - it1; - typedef typename - reverse_fold_lvalue_state< - typename reverse_fold_lvalue_state< - rest1 - , it1 - , F - >::type - , typename result_of::prior< - it1 const - >::type const - , F - >::type - type; - }; - template - struct result_of_unrolled_reverse_fold< - StateRef - , It0 - , F - , 2 - > - : reverse_fold_lvalue_state< - typename reverse_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - , typename result_of::prior< - It0 const - >::type const + template + struct result_of_it_reverse_fold::type::type + >::type> + : result_of_it_reverse_fold< + SeqSize-1 + , typename result_of::prior::type + , boost::result_of< + F( + typename add_reference::type, + typename fusion::result_of::deref::type + ) + > , F > {}; - template - struct result_of_unrolled_reverse_fold< - StateRef - , It0 + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_it_reverse_fold< + 0 + , It + , State , F - , 1 - > - : reverse_fold_lvalue_state< - StateRef - , It0 const + >::type + it_reverse_fold(mpl::int_<0>, It const&, typename State::type state, F&) + { + return state; + } + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename lazy_enable_if_c< + SeqSize != 0 + , result_of_it_reverse_fold< + SeqSize + , It + , State , F > - {}; - template - struct result_of_unrolled_reverse_fold< - StateRef - , It0 - , F - , 0 - > + >::type + it_reverse_fold(mpl::int_, It const& it, typename State::type state, F& f) { - typedef StateRef type; - }; - template - struct result_of_first_unrolledreverse_fold - { - typedef typename - result_of_unrolled_reverse_fold< - typename fusion::detail::result_of_with_decltype< - F( - StateRef, - typename fusion::result_of::deref< It0 const>::type - ) - >::type - , typename result_of::prior< - It0 const - >::type - , F - , SeqSize-1 - >::type - type; - }; - template - struct reverse_fold_impl - { - typedef typename - result_of_first_unrolledreverse_fold< - StateRef - , typename fusion::result_of::prior< typename result_of::end::type >::type - , F - , SeqSize - >::type - type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static type - call(StateRef state, Seq& seq, F f) - { - typedef - unrolled_reverse_fold< - type - , SeqSize - > - unrolled_impl; - return unrolled_impl::call( - state, - fusion::prior( fusion::end(seq)), - f); - } - }; - template - struct reverse_fold_impl<0,StateRef,Seq,F> - { - typedef StateRef type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static StateRef - call(StateRef state, Seq&, F) - { - return static_cast(state); - } - }; - template + return it_reverse_fold< + typename result_of::prior::type + , boost::result_of< + F( + typename add_reference::type, + typename fusion::result_of::deref::type + ) + > + , F + >( + mpl::int_() + , fusion::prior(it) + , f(state, fusion::deref(it)) + , f + ); + } + template::value + , bool = traits::is_segmented::value> struct result_of_reverse_fold - : reverse_fold_impl< + {}; + template + struct result_of_reverse_fold + : result_of_it_reverse_fold< result_of::size::value - , typename add_reference< - typename add_const::type - >::type - , Seq + , typename fusion::result_of::prior< typename result_of::end::type >::type + , add_reference , F > {}; + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_reverse_fold::type + reverse_fold(Seq& seq, State& state, F& f) + { + return it_reverse_fold< + typename fusion::result_of::prior< typename result_of::end::type >::type + , add_reference + , F + >( + typename result_of::size::type() + , fusion::prior( fusion::end(seq) ) + , state + , f + ); + } } namespace result_of { template struct reverse_fold - : detail::result_of_reverse_fold< - Seq - , State - , F - , traits::is_segmented::type::value - > + : detail::result_of_reverse_fold {}; } template @@ -357,10 +126,7 @@ namespace boost { namespace fusion >::type reverse_fold(Seq& seq, State const& state, F f) { - return result_of::reverse_fold::call( - state, - seq, - f); + return detail::reverse_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED @@ -371,37 +137,28 @@ namespace boost { namespace fusion >::type reverse_fold(Seq const& seq, State const& state, F f) { - return result_of::reverse_fold::call( - state, - seq, - f); + return detail::reverse_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::reverse_fold< Seq - , State const + , State , F >::type reverse_fold(Seq& seq, State& state, F f) { - return result_of::reverse_fold::call( - state, - seq, - f); + return detail::reverse_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::reverse_fold< Seq const - , State const + , State , F >::type reverse_fold(Seq const& seq, State& state, F f) { - return result_of::reverse_fold::call( - state, - seq, - f); + return detail::reverse_fold(seq, state, f); } }} diff --git a/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_iter_fold.hpp b/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_iter_fold.hpp index bf1edca5..b6101cb1 100644 --- a/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_iter_fold.hpp +++ b/include/boost/fusion/algorithm/iteration/detail/preprocessed/reverse_iter_fold.hpp @@ -11,341 +11,110 @@ namespace boost { namespace fusion { namespace detail { - template - struct reverse_iter_fold_lvalue_state - : fusion::detail::result_of_with_decltype< - F( - typename add_reference::type>::type, - It&) - > + template + struct result_of_it_reverse_iter_fold {}; - template - struct unrolled_reverse_iter_fold + template + struct result_of_it_reverse_iter_fold<0,It,State,F + , typename boost::enable_if_has_type::type> { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_3(State3 const& state3,It3 const& it3,F& f) - { - return unrolled_reverse_iter_fold< - Result - , N-4 - >::call( - f(state3,it3), - fusion::prior(it3), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return call_3( - f(state2,it2), - fusion::prior(it2), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,it1), - fusion::prior(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::prior(it0), - f); - } + typedef typename State::type type; }; - template - struct unrolled_reverse_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_2(State2 const& state2,It2 const& it2,F& f) - { - return f(state2,it2); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return call_2( - f(state1,it1), - fusion::prior(it1), - f); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::prior(it0), - f); - } - }; - template - struct unrolled_reverse_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call_1(State1 const& state1,It1 const& it1,F& f) - { - return f(state1,it1); - } - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return call_1( - f(state,it0), - fusion::prior(it0), - f); - } - }; - template - struct unrolled_reverse_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const& it0,F f) - { - return f(state, - it0); - } - }; - template - struct unrolled_reverse_iter_fold - { - template - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static Result - call(State const& state,It0 const&, F) - { - return static_cast(state); - } - }; - template - struct result_of_unrolled_reverse_iter_fold - { - typedef typename - reverse_iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::prior< - It0 const - >::type - it1; - typedef typename - reverse_iter_fold_lvalue_state< - rest1 - , it1 - , F - >::type - rest2; - typedef typename - result_of::prior::type - it2; - typedef typename - reverse_iter_fold_lvalue_state< - rest2 - , it2 - , F - >::type - rest3; - typedef typename - result_of::prior::type - it3; - typedef typename - result_of_unrolled_reverse_iter_fold< - typename reverse_iter_fold_lvalue_state< - rest3 - , it3 - , F - >::type - , typename result_of::prior< - it3 - >::type - , F - , N-4 - >::type - type; - }; - template - struct result_of_unrolled_reverse_iter_fold< - StateRef - , It0 - , F - , 3 - > - { - typedef typename - reverse_iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - rest1; - typedef typename - result_of::prior< - It0 const - >::type - it1; - typedef typename - reverse_iter_fold_lvalue_state< - typename reverse_iter_fold_lvalue_state< - rest1 - , it1 - , F - >::type - , typename result_of::prior< - it1 const - >::type const - , F - >::type - type; - }; - template - struct result_of_unrolled_reverse_iter_fold< - StateRef - , It0 - , F - , 2 - > - : reverse_iter_fold_lvalue_state< - typename reverse_iter_fold_lvalue_state< - StateRef - , It0 const - , F - >::type - , typename result_of::prior< - It0 const - >::type const + template + struct result_of_it_reverse_iter_fold::type::type + >::type> + : result_of_it_reverse_iter_fold< + SeqSize-1 + , typename result_of::prior::type + , boost::result_of< + F( + typename add_reference::type, + It const& + ) + > , F > {}; - template - struct result_of_unrolled_reverse_iter_fold< - StateRef - , It0 + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_it_reverse_iter_fold< + 0 + , It + , State , F - , 1 - > - : reverse_iter_fold_lvalue_state< - StateRef - , It0 const + >::type + it_reverse_iter_fold(mpl::int_<0>, It const&, typename State::type state, F&) + { + return state; + } + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename lazy_enable_if_c< + SeqSize != 0 + , result_of_it_reverse_iter_fold< + SeqSize + , It + , State , F > - {}; - template - struct result_of_unrolled_reverse_iter_fold< - StateRef - , It0 - , F - , 0 - > + >::type + it_reverse_iter_fold(mpl::int_, It const& it, typename State::type state, F& f) { - typedef StateRef type; - }; - template - struct result_of_first_unrolledreverse_iter_fold - { - typedef typename - result_of_unrolled_reverse_iter_fold< - typename fusion::detail::result_of_with_decltype< - F( - StateRef, - It0 const& - ) - >::type - , typename result_of::prior< - It0 const - >::type - , F - , SeqSize-1 - >::type - type; - }; - template - struct reverse_iter_fold_impl - { - typedef typename - result_of_first_unrolledreverse_iter_fold< - StateRef - , typename fusion::result_of::prior< typename result_of::end::type >::type - , F - , SeqSize - >::type - type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static type - call(StateRef state, Seq& seq, F f) - { - typedef - unrolled_reverse_iter_fold< - type - , SeqSize - > - unrolled_impl; - return unrolled_impl::call( - state, - fusion::prior( fusion::end(seq)), - f); - } - }; - template - struct reverse_iter_fold_impl<0,StateRef,Seq,F> - { - typedef StateRef type; - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - static StateRef - call(StateRef state, Seq&, F) - { - return static_cast(state); - } - }; - template + return it_reverse_iter_fold< + typename result_of::prior::type + , boost::result_of< + F( + typename add_reference::type, + It const& + ) + > + , F + >( + mpl::int_() + , fusion::prior(it) + , f(state, it) + , f + ); + } + template::value + , bool = traits::is_segmented::value> struct result_of_reverse_iter_fold - : reverse_iter_fold_impl< + {}; + template + struct result_of_reverse_iter_fold + : result_of_it_reverse_iter_fold< result_of::size::value - , typename add_reference< - typename add_const::type - >::type - , Seq + , typename fusion::result_of::prior< typename result_of::end::type >::type + , add_reference , F > {}; + template + BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED + inline typename result_of_reverse_iter_fold::type + reverse_iter_fold(Seq& seq, State& state, F& f) + { + return it_reverse_iter_fold< + typename fusion::result_of::prior< typename result_of::end::type >::type + , add_reference + , F + >( + typename result_of::size::type() + , fusion::prior( fusion::end(seq) ) + , state + , f + ); + } } namespace result_of { template struct reverse_iter_fold - : detail::result_of_reverse_iter_fold< - Seq - , State - , F - , traits::is_segmented::type::value - > + : detail::result_of_reverse_iter_fold {}; } template @@ -357,10 +126,7 @@ namespace boost { namespace fusion >::type reverse_iter_fold(Seq& seq, State const& state, F f) { - return result_of::reverse_iter_fold::call( - state, - seq, - f); + return detail::reverse_iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED @@ -371,37 +137,28 @@ namespace boost { namespace fusion >::type reverse_iter_fold(Seq const& seq, State const& state, F f) { - return result_of::reverse_iter_fold::call( - state, - seq, - f); + return detail::reverse_iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::reverse_iter_fold< Seq - , State const + , State , F >::type reverse_iter_fold(Seq& seq, State& state, F f) { - return result_of::reverse_iter_fold::call( - state, - seq, - f); + return detail::reverse_iter_fold(seq, state, f); } template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED inline typename result_of::reverse_iter_fold< Seq const - , State const + , State , F >::type reverse_iter_fold(Seq const& seq, State& state, F f) { - return result_of::reverse_iter_fold::call( - state, - seq, - f); + return detail::reverse_iter_fold(seq, state, f); } }} diff --git a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque10.hpp b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque10.hpp index ae1828a5..95cd8c1c 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque10.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque10.hpp @@ -201,7 +201,9 @@ deque(T_0 && t0 , T_1 && t1 , T_2 && t2 , T_3 && t3 , T_4 && t4 , T_5 && t5 , T_ {} template BOOST_FUSION_GPU_ENABLED - deque(Sequence const& seq, typename disable_if >::type* = 0) + deque(Sequence const& seq + , typename disable_if >::type* = 0 + , typename enable_if >::type* = 0) : base(base::from_iterator(fusion::begin(seq))) {} template diff --git a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque20.hpp b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque20.hpp index 78224634..ad069451 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque20.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque20.hpp @@ -381,7 +381,9 @@ deque(T_0 && t0 , T_1 && t1 , T_2 && t2 , T_3 && t3 , T_4 && t4 , T_5 && t5 , T_ {} template BOOST_FUSION_GPU_ENABLED - deque(Sequence const& seq, typename disable_if >::type* = 0) + deque(Sequence const& seq + , typename disable_if >::type* = 0 + , typename enable_if >::type* = 0) : base(base::from_iterator(fusion::begin(seq))) {} template diff --git a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque30.hpp b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque30.hpp index 8653217b..44a5b2b1 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque30.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque30.hpp @@ -561,7 +561,9 @@ deque(T_0 && t0 , T_1 && t1 , T_2 && t2 , T_3 && t3 , T_4 && t4 , T_5 && t5 , T_ {} template BOOST_FUSION_GPU_ENABLED - deque(Sequence const& seq, typename disable_if >::type* = 0) + deque(Sequence const& seq + , typename disable_if >::type* = 0 + , typename enable_if >::type* = 0) : base(base::from_iterator(fusion::begin(seq))) {} template diff --git a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque40.hpp b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque40.hpp index 3bfd488a..e642288e 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque40.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque40.hpp @@ -741,7 +741,9 @@ deque(T_0 && t0 , T_1 && t1 , T_2 && t2 , T_3 && t3 , T_4 && t4 , T_5 && t5 , T_ {} template BOOST_FUSION_GPU_ENABLED - deque(Sequence const& seq, typename disable_if >::type* = 0) + deque(Sequence const& seq + , typename disable_if >::type* = 0 + , typename enable_if >::type* = 0) : base(base::from_iterator(fusion::begin(seq))) {} template diff --git a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque50.hpp b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque50.hpp index 04441da6..a387708b 100644 --- a/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque50.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03/preprocessed/deque50.hpp @@ -921,7 +921,9 @@ deque(T_0 && t0 , T_1 && t1 , T_2 && t2 , T_3 && t3 , T_4 && t4 , T_5 && t5 , T_ {} template BOOST_FUSION_GPU_ENABLED - deque(Sequence const& seq, typename disable_if >::type* = 0) + deque(Sequence const& seq + , typename disable_if >::type* = 0 + , typename enable_if >::type* = 0) : base(base::from_iterator(fusion::begin(seq))) {} template