|
Boost Users : |
From: Andy Little (andy_at_[hidden])
Date: 2006-09-07 14:20:14
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 <quan/out/current.hpp>
#include <quan/matrix/out/matrix.hpp>
#include <quan/operators/binary_operator_functors.hpp>
#include <boost/fusion/sequence/io.hpp>
#include <boost/fusion/sequence.hpp>
#include <boost/ref.hpp>
// try to make a function object to wrap references
// in fusion style, with boost::ref
struct add_reference_wrapper{
template <typename T>
struct result{
typedef boost::reference_wrapper<T> type;
};
template <typename T>
typename result<T>::type
operator()(T & t)const
{
return boost::ref(t);
}
};
int main()
{
using boost::fusion::at_c;
typedef boost::fusion::vector4<
quan::current::A, quan::current::mA,
double,double
> fusion_sequence_type;
fusion_sequence_type sequence(
quan::current::A(3), quan::current::mA(2),
1,1
);
std::cout << "before : " << sequence <<'\n';
// This works OK, and and assign the sequence to itself;
std::cout << "after : " << boost::fusion::as_vector(
boost::fusion::transform(
boost::fusion::make_vector(
boost::ref(at_c<0>(sequence)), boost::ref(at_c<1>(sequence)),
boost::ref(at_c<2>(sequence)), boost::ref(at_c<3>(sequence))
),sequence,
quan::operator_plus_equals()
)
) <<'\n';
//#############################################
// But cant make a vector of non const references
boost::fusion::as_vector(
boost::fusion::transform(
sequence,add_reference_wrapper()
)
);
//#############################################
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net