On Thu, Oct 7, 2010 at 3:33 PM, OvermindDL1 <overminddl1@gmail.com> wrote:
On Wed, Oct 6, 2010 at 10:54 PM, alfC <alfredo.correa@gmail.com> wrote:
>
>
> On Oct 6, 5:33 pm, Joel de Guzman <j...@boost-consulting.com> 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<double, N> to vector<double ...>:
> I found the feature of the library that allows conversion from
> array<double, N> to vector<double*N ... >. Just by including
> #include <boost/fusion/adapted/boost_array.hpp>
> #include <boost/fusion/include/boost_array.hpp>
>
> boost::array<double, 3> ba={{1.0, 2.1, 3.2}};
> vector<double, double, double> bfv1(ba); //works.
>
> I still can the other way around.
> boost::array<double, 3> ba0(bfv1); //doesn't work
> ideas?
>
> great, I also managed to solve the original problem on how to convert
> from
> boost::array<double, N> to
> fusion::vector<quantity<T1>, quantity<T2>, ... quantity<TN> >
> 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<quantity<si::length>,
> quantity<si::time>, quantity<si::mass> > vector_of_q;
> vector_of_q fvq(
>        transform(
>                ba, // boost::array<double, 3> // 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<from_value(double const&, Q const&)>{
>                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<quantity<T1> ... quantity<TN> > to
> array<double, N> 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<double*N> to
> array<double, N>. 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/boost__array.html
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/fusion/adapted/boost_array.hpp>
#include <boost/fusion/include/boost_array.hpp>
...
boost::array<double, 3> boostarr={{1.0, 2.1, 3.2}};
vector<double, double, double> fusionvec(boostarr); //now works

I still can't do the other way around:

boost::array<double, 3> boostarr2(fusionvec); //doesn't work
ideas?

_______________________________________________
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.