#include #include #include #include #include #include #include #include #include class A { int i; public: A(int i):i(i){} void set(int i){this->i=i;} int get()const{return i;} }; BOOST_FUSION_ADAPT_CLASS(A,(int,int,obj.get(),obj.set(val))) struct B { int i; }; BOOST_FUSION_ADAPT_STRUCT(B,(int,i)) using namespace boost::fusion; template struct FWrapper { typedef int result_type; template void impl(It it,boost::mpl::true_)const { std::cout<<"direct"; return f(deref(it)); } template void impl(It it,boost::mpl::false_)const { std::cout<<"indirect"; result_of::value_of::type val=deref(it); f(val); deref(it)=val; } template int operator()(int,It it)const { typedef typename result_of::deref::type dt; typedef typename result_of::value_of::type vt; typedef boost::mpl::or_,boost::is_convertible::type> > c; impl(it,boost::mpl::bool_()); return 0; } F f; }; template void ref_for_each(Seq&seq) { iter_fold(seq,0,FWrapper()); } struct F { typedef void result_type; void operator()(int&i)const { std::cout<<" int& "<(a); ref_for_each(const_cast(a)); B b={0}; ref_for_each(b); ref_for_each(const_cast(b)); }