2010/10/8 Thomas Heller <thom.heller@googlemail.com>
alfC wrote:

>
>
> On Oct 7, 5:13 pm, OvermindDL1 <overmind...@gmail.com> wrote:
>> On Thu, Oct 7, 2010 at 5:42 PM, Alfredo Correa <alfredo.cor...@gmail.com>
>> wrote:
>> > On Thu, Oct 7, 2010 at 3:33 PM, OvermindDL1 <overmind...@gmail.com>
>> > wrote:
>> >> You do know that based on this:
>>
>> >>
http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/adap...
>> >> 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
>>
>> Ah, heh, got lost in the noise and I missed it.
>>
>> On Thu, Oct 7, 2010 at 5:42 PM, Alfredo Correa <alfredo.cor...@gmail.com>
>> wrote:
>> > I still can't do the other way around:
>>
>> > boost::array<double, 3> boostarr2(fusionvec); //doesn't work
>> > ideas?
>>
>> I know that would not work because that is still a 'custom' type as
>> far as fusion is concerned, and only free functions can work on it, a
>> constructor is obviously not a free function, so you need to write a
>> free function to do it (probably called 'copy', probably using
>> fusion's foreach to copy each element one to the other, should be
>> pretty well optimized out thanks to the template-magic).
>
> no luck. I can't make it work. First I tried with "for_each" and
> didn't manage to put together the code because I need to copy one
> sequence from the other and the for_each doesn't keep track of the
> index. So I tried with "transform", the code compiles but does nothing
> to the array.
>
> boost::array<double, 3> ba0;
> boost::fusion::transform(ba0, bfv1, copy());
>
> where
> struct copy{
> typedef void result_type;
> void operator()(double& lhs, double const& rhs) const{
> lhs = rhs;
> }
> };
>
> ba0 is still undefined after running this.
>
> Obviously I am getting Boost.Fusion wrong.
>
> Thanks,
> Alfredo

You will find a version using fold attached.
What it does, is that it increases the size of the boost::array passed in as
state by one for every element in the fusion sequence and copies over the
elements. There could be a more elegant solution to the problem ;)

Thomas, thanks so much for the code. Unfortunately it doesn't work (maybe it is my compiler?)

$ c++ -v
gcc 4.4.3
$ c++ fusion_test.cpp
$ ./a.out
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::out_of_range> >'
  what():  attempt to access element of an empty array
Aborted

Thanks,
Alfredo
 

Cheers

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