Hi! please see my answer below. On Sat, Nov 12, 2011 at 12:03 PM, Gennadiy Rozental <rogeeff@gmail.com>wrote:
Hi,
Now I am trying to perform transform which mutates:
int main() { B b1, b2; auto z1 = fusion::make_list( b1, b2 ); !!! create a list of copied Bs
auto z2 = fusion::as_list( fusion::transform( z1, make_c() ) ); !!! copies Bs again
return 0; }
You need to make a list of references to Bs: This is a slighly modified code which compiled in msvc #include <boost/fusion/container/list/list.hpp> #include <boost/fusion/container/list/convert.hpp> #include <boost/fusion/container/generation/make_list.hpp> #include <boost/fusion/algorithm/transformation/transform.hpp> #include <boost/ref.hpp> using namespace boost; struct C {}; struct B { C make_c() { return C(); } }; struct make_c { template<typename Sig> struct result; template <typename T> struct result<make_c(T&)> { typedef C type; }; template <typename T> struct result<make_c(T)> { typedef C type; }; template <typename T> C operator()(T& t) const { return t.make_c(); } }; int main() { B b1, b2; auto z1 = fusion::make_list( ref(b1), ref(b2) ); auto z2 = fusion::as_list( fusion::transform( z1, make_c() ) ); return 0; } Regards, Ovanes