/*============================================================================= Copyright (c) 2012 Joel falcou Distributed under 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) ==============================================================================*/ #include #include #include #include #include #include #include #include struct foo { double d; float f; short c; }; BOOST_FUSION_ADAPT_STRUCT(foo,(double,d)(float,f)(short,c)) template class composite_reference : public boost::mpl:: transform < typename boost::fusion::result_of:: as_vector::type , boost::add_reference >::type { public: typedef typename boost::mpl:: transform < typename boost::fusion::result_of:: as_vector::type , boost::add_reference >::type parent; composite_reference(T& src) : parent( src ) {} composite_reference(parent& src) : parent(src) {} composite_reference& operator=(T& src) { static_cast(*this) = static_cast(src); return *this; } composite_reference& operator=(parent const& src) { static_cast(*this) = src; return *this; } }; int main(int,char**) { foo f; composite_reference ref_f(f); boost::fusion::at_c<0>(ref_f) = 1.2; boost::fusion::at_c<1>(ref_f) = 1.2f; boost::fusion::at_c<2>(ref_f) = 12; std::cout << f.d << " " << f.f << " " << f.c << "\n"; }