diff --git a/test/Jamfile b/test/Jamfile index 59ec32b2..21fd42dd 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -134,10 +134,11 @@ import testing ; [ run sequence/define_struct.cpp : : : : ] [ run sequence/define_struct_inline.cpp : : : : ] [ run sequence/define_assoc_struct.cpp : : : : ] - [ run sequence/define_tpl_struct.cpp : : : : ] + [ run sequence/define_tpl_struct.cpp : : : : ] [ run sequence/define_tpl_struct_inline.cpp : : : : ] [ run sequence/define_assoc_tpl_struct.cpp : : : : ] [ run sequence/std_tuple_iterator.cpp : : : : ] + [ run sequence/ref_vector.cpp : : : : ] [ run functional/fused.cpp : : : : ] [ run functional/fused_function_object.cpp : : : : ] diff --git a/test/sequence/ref_vector.cpp b/test/sequence/ref_vector.cpp new file mode 100644 index 00000000..8bd0929b --- /dev/null +++ b/test/sequence/ref_vector.cpp @@ -0,0 +1,64 @@ +/*============================================================================= + 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"; +}