/*============================================================================= Copyright (c) 2003 Joel de Guzman Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #if !defined(FUSION_ALGORITHM_DETAIL_FOLD_IPP) #define FUSION_ALGORITHM_DETAIL_FOLD_IPP #include #include #include #include #include #include namespace boost { namespace fusion { namespace detail { template struct fold_apply { typedef typename F::template apply< typename meta::value_of::type, State >::type type; }; template struct static_fold; template struct next_result_of_fold { typedef typename static_fold< typename meta::next::type , Last , typename fold_apply::type , F >::type type; }; template struct static_fold { typedef typename mpl::if_< is_same , mpl::identity , next_result_of_fold >::type result; typedef typename result::type type; }; // terminal case template inline State const& fold(First const&, Last const&, State const& state, F const&, mpl::true_) { return state; } // non-terminal case template inline typename static_fold::type fold( First const& first , Last const& last , State const& state , F const& f , mpl::false_) { return detail::fold( fusion::next(first) , last , f(*first, state) , f , is_same::type, Last>() ); } }}} #endif