Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] more trouble with transform
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2011-11-12 06:20:07


Hi!

please see my answer below.

On Sat, Nov 12, 2011 at 12:03 PM, Gennadiy Rozental <rogeeff_at_[hidden]>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



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net