#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template class variable_list_member { public: typedef typename boost::mpl::apply1::type member_type; member_type& get() {return t;} const member_type& get()const{return t;} private: member_type t; }; template > class variable_list_seq: private boost::mpl::fold< Sequence, boost::mpl::empty_base, boost::mpl::inherit< boost::mpl::_1, variable_list_member< boost::mpl::_2, typename boost::mpl::lambda::type > > >::type { typedef typename boost::mpl::lambda::type op_type; public: template typename variable_list_member::member_type & get() { return static_cast&>(*this).get(); } template const typename variable_list_member::member_type & get()const { return static_cast&>(*this).get(); } }; /* front end to variable_list_seq hiding the use of MPL sequences */ #define VARIABLE_LIST_TEMPLATE_PARM(z,n,var) \ typename BOOST_PP_CAT(var,n) BOOST_PP_EXPR_IF(n,=boost::mpl::na) template class variable_list: public variable_list_seq > { }; #undef VARIABLE_LIST_TEMPLATE_PARM /* cartesian variable list */ template class product_variable_list_member { public: typedef typename boost::mpl::apply2< Op, typename P::first, typename P::second >::type member_type; member_type& get() {return t;} const member_type& get()const{return t;} private: member_type t; }; template struct pair_with:boost::mpl::pair{}; template struct sequence_product: boost::mpl::fold< Sequence1, boost::mpl::vector0<>, boost::mpl::joint_view< boost::mpl::_1, boost::mpl::transform< Sequence2, pair_with > > > {}; template< typename Sequence1,typename Sequence2, typename Op=std::pair > class product_variable_list_seq: private boost::mpl::fold< typename sequence_product::type, boost::mpl::empty_base, boost::mpl::inherit< boost::mpl::_1, product_variable_list_member< boost::mpl::_2, typename boost::mpl::lambda::type > > >::type { typedef typename boost::mpl::lambda::type op_type; public: template typename product_variable_list_member< boost::mpl::pair,op_type >::member_type & get() { return static_cast< product_variable_list_member< boost::mpl::pair,op_type>&>(*this).get(); } template const typename product_variable_list_member< boost::mpl::pair,op_type >::member_type & get()const { return static_cast< const product_variable_list_member< boost::mpl::pair,op_type>&>(*this).get(); } }; /**************** testing ****************/ #include template struct my_type{typedef T* type;}; int main() { typedef variable_list vl_type; vl_type v; const vl_type& vc=v; v.get()=5; v.get()='a'; v.get()=1.0; std::cout<<"v.get()=="<()<()=="<()<()=="<()<, my_type > vl_type2; vl_type2 v2; const vl_type2& vc2=v2; int x=5; v2.get()=&x; v2.get()="hello"; std::cout<<"*(v2.get())=="<<*(vc2.get())<()=="<()<, boost::mpl::vector > pvl_type; pvl_type pv; const pvl_type& pvc=pv; pv.get()=std::make_pair(0,1.0); pv.get()=std::make_pair(1,"boost"); pv.get()=std::make_pair('a',2.0); pv.get()=std::make_pair('b',"bye"); std::cout<<"pv.get()==("<< pvc.get().first<<","<< pvc.get().second<<")"<()==("<< pvc.get().first<<","<< pvc.get().second<<")"<()==("<< pvc.get().first<<","<< pvc.get().second<<")"<()==("<< pvc.get().first<<","<< pvc.get().second<<")"<