/*============================================================================= Copyright (c) 2001-2006 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_FOLD_05052005_1211) #define FUSION_FOLD_05052005_1211 #include #include #include #include #include #include #include #include #include namespace boost { namespace fusion { namespace detail { // Unary arguments version template struct apply_fold_result { template struct apply { typedef typename F::template result::type type; }; }; template struct fold_apply : mpl::apply, typename result_of::value_of::type, State> {}; template struct static_fold; template struct next_result_of_fold { typedef typename static_fold< typename result_of::next::type , Last , typename fold_apply::type , F >::type type; }; template struct static_fold { typedef typename mpl::if_< result_of::equal_to , 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 , result_of::equal_to::type, Last>() ); } }}} #endif