Selecting one element per fusion sequence using mpl::int_s
Dear all,
I am trying to create a fusion sequence whose elements are non-const references to the elements of given set of sequences. In particular, for a given sequence of integral constants, say vector< int_<2>, int_<1> >, and two fusion sequences, say X = vector< X0, X1, X2, X3 > and Y = vector< Y0, Y1, Y2 >, I would like to create the following sequence
R = vector< X2&, Y1& >, such that at<0>(R) == at<2>(X) and at<1>(R) == at<1>(Y).
I am using fusion::transform to achieve the above but the transform function takes the sequences as const references so I end up with R = vector
2014-06-29 8:38 GMT+08:00 gsermaid
Dear all,
I am trying to create a fusion sequence whose elements are non-const references to the elements of given set of sequences. In particular, for a given sequence of integral constants, say vector< int_<2>, int_<1> >, and two fusion sequences, say X = vector< X0, X1, X2, X3 > and Y = vector< Y0, Y1, Y2 >, I would like to create the following sequence
R = vector< X2&, Y1& >, such that at<0>(R) == at<2>(X) and at<1>(R) == at<1>(Y).
I am using fusion::transform to achieve the above but the transform function takes the sequences as const references so I end up with R = vector
, which is not what I want. Below is my code; any ideas on how to get a sequence of non-const references would be greatly appreciated. Thanks for reading! #include
#include #include #include #include #include #include <iostream>
using namespace boost::fusion; using boost::mpl::int_;
using my_ints = vector< int_<2>, int_<1> >; using my_x = vector
; using my_y = vector ; using joined = vector ; struct my_functor {
template
typename result_of::at ::type operator()(I& i, Seq& seq) const { return boost::fusion::at<I>(seq); } }; int main() {
my_ints ints; my_x x(-2, 3.5, 15, -1.3); my_y y(4, 10.1, 100); joined jv(x, y);
auto tv = transform(ints, jv, my_functor()); std::cout << tv << std::endl; // prints (15 10.1)
// these two fail to compile because the first argument is const-qualified BOOST_MPL_ASSERT(( boost::is_same< decltype(at_c<0>(tv)), unsigned& > )); BOOST_MPL_ASSERT(( boost::is_same< decltype(at_c<1>(tv)), float& > )); }
For now, you can take this file: https://github.com/jamboree/fusion/blob/develop/include/boost/fusion/support... Include it, and use it as: auto tv = transform(ints, boost::ref(jv), my_functor()); HTH
participants (2)
-
gsermaid
-
TONGARI J