Hi,
I am trying to convert a boost::array into a fusion::vector.
reinterpreting the memory from boost::array. It works for tuples but
not fusion::vector, why is that. Is there a way to make it work? ( I
was hoping that the memory layout is the same to make conversion from
one to the other very easy.)
#include
#include
#include
#include<iostream>
#include
using std::clog; using std::endl;
int main(){
boost::array ba={{1.0, 2.1, 3.2}};
clog << "ba: " << ba[0] << ", " << ba[1] << ", " << ba[2] << endl;
using namespace boost::fusion;
vector bfv( reinterpret_cast&>(ba) ); //doesn't work as expected
clog << "bfv: " << at_c<0>(bfv) << ", "<< at_c<1>(bfv) << ", " <<
at_c<2>(bfv) << endl;
using boost::tuple;
tuple btt(reinterpret_cast&>(ba) ); // works!
clog << "btt: " << btt.get<0>() << ", "<< (btt).get<1>() << ", " <<
(btt).get<2>() << endl;
return 0;
}
outputs:
ba: 1, 2.1, 3.2 //original data
bfv: -9.25597e+61, -2.35344e-185, 4.87507e-270 //not expected
btt: 1, 2.1, 3.2 //works!
Let me give some context, the reason I am doing this is that I need to
interface fusion::vector of boost::quantities (all have the sizeof
double) and adimensionalize the list of quantities into an array of
doubles and vise-versa
In reality, the final goal is to get this to work:
boost::array ba={{1.0, 2.1, 3.2}};
vectorsi::length, quantitysi::time , quantitysi::mass >
bfv( reinterpret_castsi::length,
quantitysi::time , quantitysi::mass >&>(ba) );
(or other generic option to go from array to
vector)
but since I can't make it work with simple 'doubles' I am asking why
this could be done.
Thank you again,
Alfredo