On Thu, Oct 7, 2010 at 3:33 PM, OvermindDL1
On Wed, Oct 6, 2010 at 10:54 PM, alfC
wrote: On Oct 6, 5:33 pm, Joel de Guzman
wrote: On 10/7/2010 3:53 AM, alfC wrote:
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.)
Don't do that. It will *never* be guaranteed to work even if it works now. The memory layout of fusion::vector is an internal implementation detail and can change anytime.
It is not only not guaranteed, it does not work at present. Any two cents why is that fusion::vector may (do?) implement a non obvious memory layout?
I solved the problem of array
to vector : I found the feature of the library that allows conversion from array to vector . Just by including #include #include boost::array
ba={{1.0, 2.1, 3.2}}; vector bfv1(ba); //works. I still can the other way around. boost::array
ba0(bfv1); //doesn't work ideas? great, I also managed to solve the original problem on how to convert from boost::array
to fusion::vector thanks to your other posting suggesting using fusion::transform quantity<T> can be constructed from a double with quantity<T>::from_value(double)
The line of code that does this is
typedef boost::fusion::vector
si::length, quantitysi::time, quantitysi::mass > vector_of_q; vector_of_q fvq( transform( ba, // boost::array // incld"/fusion/array.hpp"!!
vector_of_q(), from_value() ) );
where "from_value" is defined by
struct from_value{ // binary fusion transformation template <typename SignatureT> struct result; template <typename Q> struct result
{ typedef Q type; }; template<typename Q> Q operator()(double const& value, Q const&) const{ return Q::from_value(value); } }; I had to use the *binary* version of transform because the type of the result depends on the destination fusion::vector.
The other way around from vector
to array should be easier (because the destination type is always double by using the quantity<T>::value() ) but I didn't managed because I didn't find the way to convert from vector to array . ideas? Thank you for making fusion, it is an incredible library once you realize what it is for. Alfredo
You do know that based on this:
http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/adapted/boo... boost::array is already adapted as a fusion container and can be used directly, as soon as you include the proper hpp that is?
yes, thank you, that what I wrote in my last post . I can make this work
#include
Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Sie haben diese Nachricht erhalten, da Sie der Google Groups-Gruppe Boost Users beigetreten sind. Wenn Sie Nachrichten in dieser Gruppe posten möchten, senden Sie eine E-Mail an boostusers@googlegroups.com. Wenn Sie aus dieser Gruppe austreten möchten, senden Sie eine E-Mail an boostusers+unsubscribe@googlegroups.com
. Besuchen Sie die Gruppe unter http://groups.google.com/group/boostusers?hl=de, um weitere Optionen zu erhalten.