// //ModificationHistor: // 2010-07-09 // cp'ed from // http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/if_recur.hpp // #ifndef BOOST_FUSION_IF_RECUR_HPP_20100709_1405UTC #define BOOST_FUSION_IF_RECUR_HPP_20100709_1405UTC // Copyright Larry Evans 2010 // // $Id: if_recur.hpp,v 1.4 2010/07/10 12:46:44 evansl Exp evansl $ // $Date: 2010/07/10 12:46:44 $ // $Revision: 1.4 $ #include namespace boost { namespace fusion { namespace aux { namespace if_recur { template < class State , bool Result=false > struct always { typedef bool result_type ; static result_type call ( State const& state ) { return Result; } }; template < class State > struct identity { typedef State result_type ; static State call ( State const& state ) { return state; } }; template < unsigned Index , typename... Args > struct at_c ; template < unsigned Index , typename Head , typename... Tail > struct at_c < Index , Head , Tail... > { typedef at_c < Index-1 , Tail... > tail_at_c ; typedef typename tail_at_c::result_type result_type ; static result_type call ( Head const& head , Tail const&... tail ) { return tail_at_c::call(tail...); } }; template < typename Head , typename... Tail > struct at_c < 0 , Head , Tail... > { typedef Head result_type ; static Head call ( Head const& head , Tail const&... ) { return head; } }; }//exit if_recur namespace }//exit aux namespace //Notation: // // X -> Y = function from "type" X to "type" Y. // // State = some Kind of "state" //Purpose: // Almost the same as section 12.5 equation 1) of: // http://www.thocp.net/biographies/papers/backus_turingaward_lecture.pdf // The correspondences between this and that equaton is: // // this equation 1) // ---- ----------- // if_recur f // mpl::not_ p // ThenDown j // NowNow i // NowUp h // ElseBtm g // template < class StateNow//current state , class Recur=aux::if_recur::always//functor: State -> bool. , class ThenDown=aux::if_recur::identity//Functor: State -> State. , class NowNow=aux::if_recur::identity//Functor: State -> State. , class NowUp=aux::if_recur::at_c<1,StateNow,StateNow>//Functor: (State,State) -> State. , class ElseBtm=aux::if_recur::identity//Functor: State -> State. > struct if_recur { typedef typename boost::result_of < ElseBtm(StateNow) >::type result_type ; static result_type call ( StateNow const& state_now ) { indent_undent_cout iuc; if(Recur::call(state_now)) { return NowUp::call ( NowNow::call(state_now) , call ( ThenDown::call(state_now) ) ); } else { return ElseBtm::call(state_now); } } }; }//exit fusion namespace }//exit boost namespace #endif