I've got a Boost.Fusion sequence of elements that need to be initialized one each with the elements of another sequence. When I'd not use Fusion, this would look like:
class A {
A1 a;
A2 b;
A3 c;
};
class B {
B1 a;
B2 b;
B3 c;
B( const A& o ) : a(o.a), b(o.b), c(o.c) {}
};
My only idea to realize this with Fusion vectors is something like
BVector b( transform( AVector(), magic_functor() ) );
In this idea, magic_functor
would have a result type of Bi
for an Ai
and perform the construction in its operator()
.
However, magic_functor
would have to know the right type to cast to, which would result in duplicate logic.
Is there any better way of fusion-ifying the initialization?
If I understand correctly, you want to replace your classes with
fusion::vector
s, like this:In this case, you can initialize
B
fromA
simply by usingvector
's "copy" constructor (it is not a real copy constructor since it can accept any forward sequence):It should be noted that
A
andB
does not even need to be the same kind of sequence: you can initialize afusion::vector
from afusion::list
, or afusion::set
from amyCustomForwardSequence
.