//WARNING@2010-09-29: // 1) Don't try to compile this code with that from: /* http://svn.boost.org/svn/boost/sandbox/variadic_templates/ */ // otherwise, you'll get a compile-time error about // mpl::vector0. // // 2) Only works with variadic fusion: /* http://svn.boost.org/svn/boost/sandbox/SOC/2009/fusion/ */ // otherwise, you'll get compile-time error in category_of.hpp // about joine_view<...>& not being class, struct, or union. // //Purpose: // Answer question in post: // // http://article.gmane.org/gmane.comp.lib.boost.user/62386 // //References: // [ffold] // http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html // /fusion/algorithm/iteration/functions/fold.html // #include #include #include #include #include #include namespace fold_join { struct join_ftor /**@brief * Forward decl of functor for joining 2 fusion sequences. */ ; template struct tu { tu(T a_t):my_t(a_t){} T my_t; friend std::ostream& operator<< ( std::ostream& sout , tu const& x ) { sout<<"tu<"<("< struct result_of < fold_join::join_ftor(LhSequence,RhSequence) > /**@brief * As specified by table 1.37 Requirement for Parameter f * in [ffold]. */ : fusion::result_of::join { }; }//exit boost namespace namespace fold_join { struct join_ftor /**@brief * modified from 'struct make_string' from [ffold]. */ { template typename boost::result_of::type operator()(LhSequence& lhs, RhSequence& rhs)const { return boost::fusion::join(lhs,rhs); } }; }//exit fold_join namespace using namespace boost; using namespace fold_join; int main(void) { typedef fusion::vector<> vec0; typedef fusion::vector, tu, tu > t1; typedef fusion::vector, tu, tu > t2; typedef fusion::vector, tu, tu > t3; vec0 state0; t1 v1(100,'b',300.1); t2 v2(100,'b',300.1); t3 v3(100,'b',300.1); std::cout<<"v1="< vv(v1,v2,v3); join_ftor joiner; auto fold_vv=fusion::fold(vv,state0,joiner); std::cout <<"fold(vv,state0,join_ftor())=" <