[fusion] transform a vector of values to refs

Hi,
I am trying to transform from a fusion vector of values to a fusion vector
of non-const references to those values, the ultimate aim being to assign the
original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it
for any fusion sequence. How can I do that? Current efforts follows:
regards
Andy Little
#include

"Andy Little"
Hi,
I am trying to transform from a fusion vector of values to a fusion vector of non-const references to those values, the ultimate aim being to assign the original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it for any fusion sequence. How can I do that?
You can find an example of exactly that on the zip_iterator_fusion branch of boost/iterator/zip_iterator.hpp HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com

"David Abrahams"
"Andy Little"
writes: Hi,
I am trying to transform from a fusion vector of values to a fusion vector of non-const references to those values, the ultimate aim being to assign the original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it for any fusion sequence. How can I do that?
You can find an example of exactly that on the zip_iterator_fusion branch of boost/iterator/zip_iterator.hpp
Yikes. I don't really understand what I am meant to do with that. I will have to
study it in more detail.
I reckon that a get_ref_vector(fusion::vector) would be quite useful. I guess
there isnt much difference to a view though?.
Anyway I have continued hacking away and so here is my latest efforts, using
fusion to do a dot product of two vectors.
Maybe it would be a useful example in the fusion docs?. Anyway here it is FWIW:
regards
Andy Little
--------------------------
// Copyright Andrew Little 2006
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See QUAN_ROOT/quan_matters/index.html for documentation.
/*
dot product of two vectors using fusion.
The input vectors are just raw fusion sequences
*/
#include

"Andy Little"
Anyway I have continued hacking away and so here is my latest efforts, using fusion to do a dot product of two vectors. Maybe it would be a useful example in the fusion docs?. Anyway here it is FWIW:
A couple of bugs found in my code, as detailed below . ---> Also I found I had to comment out the specialisation of as_vector<0> in < boost/fusion/sequence/conversion/detail/as_vector.hpp> in the Boost Review version to get it to compile OK in GCC4.0.1 I havent tried the CVS version of the file but it looks unchanged relative to my version. regards Andy Little <...>
// more arg reversing template <typename F> struct reverse_f_args{
template
struct result{ typedef typename F:: template result< Rhs,Lhs >::type type; }; template typename result ::type operator()( Rhs const & rhs, Lhs const & lhs )const { F f;
- f(lhs,rhs); + return f(lhs,rhs); ---------------------- <...>
// do the dot_product
- - result_type result = boost::fusion::fold( - + + result_type result = 0; + + boost::fusion::fold( -------------------------------------------------
boost::fusion::transform(seq1,seq2,quan::operator_times()), boost::ref(result), quan::fusion::reverse_assign_f_argsquan::operator_plus_equals() ); assert(quan::compare(result,30,1e-12) ==0); std::cout << result <<'\n';
} -----------------------------

Andy Little wrote:
"Andy Little"
wrote
Also I found I had to comment out the specialisation of as_vector<0> in < boost/fusion/sequence/conversion/detail/as_vector.hpp> in the Boost Review version to get it to compile OK in GCC4.0.1
I havent tried the CVS version of the file but it looks unchanged relative to my version.
Hmmm... Could you provide a minimal code that exhibits the problem? Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

"Joel de Guzman"
Andy Little wrote:
"Andy Little"
wrote Also I found I had to comment out the specialisation of as_vector<0> in < boost/fusion/sequence/conversion/detail/as_vector.hpp> in the Boost Review version to get it to compile OK in GCC4.0.1
I havent tried the CVS version of the file but it looks unchanged relative to my version.
Hmmm... Could you provide a minimal code that exhibits the problem?
Sure. Just include the as_vector header. Note this is the review version, not
CVS
#include
gcc --version gcc (GCC) 4.0.1 (Indiana Concepts release 2) Copyright (C) 2005 Free Software Foundation, Inc. Copyright (C) 2005 Trustees of Indiana University. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
compile output:
E:\projects\Test>gcc -I"C:\boost\include\boost-1_33_1" -I"C:/quan/quan-trunk" -c
test.cpp
C:/boost/include/boost-1_33_1/boost/fusion/sequence/conversion/detail/as_vector.
hpp: In static member function 'static typename boost::fusion::detail::as_vector
<0>::apply<Iterator>::type boost::fusion::detail::as_vector<0>::call(Iterator)':
C:/boost/include/boost-1_33_1/boost/fusion/sequence/conversion/detail/as_vector.
hpp:42: error: invalid use of undefined type 'struct boost::fusion::vector

Andy Little wrote:
"Joel de Guzman"
wrote in message news:edu1li$1sf$2@sea.gmane.org... Andy Little wrote:
"Andy Little"
wrote Also I found I had to comment out the specialisation of as_vector<0> in < boost/fusion/sequence/conversion/detail/as_vector.hpp> in the Boost Review version to get it to compile OK in GCC4.0.1 I havent tried the CVS version of the file but it looks unchanged relative to my version. Hmmm... Could you provide a minimal code that exhibits the problem?
Sure. Just include the as_vector header. Note this is the review version, not CVS
#include
Sorry I can't reproduce it. I don't have g++ 4.0.1 at the moment. I tried it with VC7.1, VC8.0, G++ 3.4 and Comeau 4.3.3. All the compilers compile it just fine. Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

Andy Little wrote:
"David Abrahams"
wrote "Andy Little"
writes: Hi,
I am trying to transform from a fusion vector of values to a fusion vector of non-const references to those values, the ultimate aim being to assign the original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it for any fusion sequence. How can I do that? You can find an example of exactly that on the zip_iterator_fusion branch of boost/iterator/zip_iterator.hpp
Yikes. I don't really understand what I am meant to do with that. I will have to study it in more detail. I reckon that a get_ref_vector(fusion::vector) would be quite useful. I guess there isnt much difference to a view though?. Anyway I have continued hacking away and so here is my latest efforts, using fusion to do a dot product of two vectors. Maybe it would be a useful example in the fusion docs?. Anyway here it is FWIW:
Yes, definitely! I'll have to ask for documentation though. A simple readme file is ok, plus, lots of comments. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

"Joel de Guzman"
Andy Little wrote:
Maybe it would be a useful example in the fusion docs?. Anyway here it is FWIW:
Yes, definitely! I'll have to ask for documentation though. A simple readme file is ok, plus, lots of comments.
OK. Bear in mind that its reliant 3 functors, multiply, add, and add-and-assign.
In order to be agnostic regarding type deduction schemes ( my own, phoenix,
lambda etc), my thought is to present particular versions of the functors
implemented using Boost.Typeof.
For the assignment one it needs to be implemented in terms of
boost::reference_wrapper anyway and with the Lvalue as the right hand argument,
which is AFAICS particular to the use of fold in fusion.
for example :
struct example_multiply{
template

Andy Little wrote:
"Joel de Guzman"
wrote Andy Little wrote:
Maybe it would be a useful example in the fusion docs?. Anyway here it is FWIW: Yes, definitely! I'll have to ask for documentation though. A simple readme file is ok, plus, lots of comments.
OK. Bear in mind that its reliant 3 functors, multiply, add, and add-and-assign. In order to be agnostic regarding type deduction schemes ( my own, phoenix, lambda etc), my thought is to present particular versions of the functors implemented using Boost.Typeof. For the assignment one it needs to be implemented in terms of boost::reference_wrapper anyway and with the Lvalue as the right hand argument, which is AFAICS particular to the use of fold in fusion.
for example :
struct example_multiply{
template
struct result{ typedef BOOST_TYPEOF_TPL(A() * B()) type; }; template
typename result::type operator(A const & a, B const & b) { return a * b; } }; Boost.Typeof will after all be in the next release alongside Boost.Fusion Is that acceptable?
Sounds good. Okidoki. Cheers, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

"Joel de Guzman"
Sounds good. Okidoki.
Great. I will see if I can get on with it, rather than spend more time mucking about with fusion ;-) regards Andy Little

"Joel de Guzman"
Sounds good. Okidoki.
OK. Its done. Its called fusion_example.zip and in The Boost vault in generic programming directory: http://tinyurl.com/hw7js There may be some typo errors and I could write in more detail, but there should be eneough there to start with anyawy. regards Andy Little

Andy Little wrote:
"Joel de Guzman"
wrote in message news:edv1e0$n73$1@sea.gmane.org... Sounds good. Okidoki.
OK. Its done. Its called fusion_example.zip and in The Boost vault in generic programming directory:
There may be some typo errors and I could write in more detail, but there should be eneough there to start with anyawy.
Cool! I'll have a look at it as soon as I get some time; possibly over the weekend. Cheers! -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net

"Joel de Guzman"
Andy Little wrote:
"Joel de Guzman"
wrote in message news:edv1e0$n73$1@sea.gmane.org... Sounds good. Okidoki.
OK. Its done. Its called fusion_example.zip and in The Boost vault in generic programming directory:
There may be some typo errors and I could write in more detail, but there should be eneough there to start with anyawy.
Cool! I'll have a look at it as soon as I get some time; possibly over the weekend.
Actually I am now thinking of extending the dot.doc so that it tracks development of a matrix library using fusion, which it now looks is quite feasible and practical at least for small matrices. regards Andy Little

"Andy Little"
"David Abrahams"
wrote "Andy Little"
writes: Hi,
I am trying to transform from a fusion vector of values to a fusion vector of non-const references to those values, the ultimate aim being to assign the original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it for any fusion sequence. How can I do that?
You can find an example of exactly that on the zip_iterator_fusion branch of boost/iterator/zip_iterator.hpp
Yikes. I don't really understand what I am meant to do with that. I will have to study it in more detail.
mpl::transform

"David Abrahams"
"Andy Little"
writes: "David Abrahams"
wrote "Andy Little"
writes: Hi,
I am trying to transform from a fusion vector of values to a fusion vector of non-const references to those values, the ultimate aim being to assign the original sequence from another sequence.
The code below works ok with make_vector, but I want to be able to automate it for any fusion sequence. How can I do that?
You can find an example of exactly that on the zip_iterator_fusion branch of boost/iterator/zip_iterator.hpp
Yikes. I don't really understand what I am meant to do with that. I will have to study it in more detail.
mpl::transform
> ref_tuple(( value_tuple ));
Yes if it does what it says on the tin :-) Now all I need is a matrix iterator, but I guess I should figure that out myself. regards Andy Little
participants (3)
-
Andy Little
-
David Abrahams
-
Joel de Guzman