Ovanes Markarian writes:
You need to make a list of references to Bs:
B b1, b2;
auto z1 = fusion::make_list( ref(b1), ref(b2) );
auto z2 = fusion::as_list( fusion::transform( z1, make_c() ) );
This one indeed works, but what I am really after is something like this:
auto z1 = fusion::make_list( B(), B() );
auto z2 = fusion::as_list( fusion::transform( z1, make_c() ) );
I know first line will move constructed instances into list z1. Next I need to
mutate them and adding boost::ref around B() is impossible. In reality my use
case somewhat more complicated. Something like this:
#include
#include
#include
#include
namespace fusion=boost::fusion;
struct C {};
struct B {
C make_c() { return C(); }
};
class A {
public:
B make_b() const { return B(); }
};
//____________________________________________________________________________//
struct make_b {
template<typename Sig> struct result;
template <typename T>
struct result
{
typedef B type;
};
template <typename T>
struct result
{
typedef B type;
};
template <typename T>
B
operator()(T const& t) const { return t.make_b(); }
};
struct make_c {
template<typename Sig> struct result;
template <typename T>
struct result
{
typedef C type;
};
template <typename T>
struct result
{
typedef C type;
};
template <typename T>
C
operator()(T& t) const { return t.make_c(); }
};
template<typename T>
void
do_something( T const& t )
{
}
int
main()
{
auto z1 = fusion::as_list( fusion::transform( fusion::make_list( A(), A() ),
make_b() ) );
size_t size = 1; // I calculate size here, irrelevant to the question
while( size-- > 0 )
do_something( fusion::as_list( fusion::transform( z1, make_c() ) ) );
return 0;
}
Same problem.
Gennadiy