Interaction between runtime and fusion sequences
Further to my question C++ Tuple of Boost.Range - get Tuple of element types?
I have the following:
TupleOfRanges ranges;
TupleOfElements elements;
std::vector<int> offsets;
All containers (both meta and runtime) are of size N
. I would like to write code that does the following:
boost::fusion::at_c<0>(elements)
= *(boost::begin(boost::fusion::at_c<0>(ranges)) + offset[0]);
boost::fusion::at_c<1>(elements)
= *(boost::begin(boost::fusion::at_c<1>(ranges)) + offset[1]);
// ...
boost::fusion::at_c<N>(elements)
= *(boost::begin(boost::fusion::at_c<N>(ranges)) + offset[N]);
I have tried writing this using Fusion's trans开发者_如何学Pythonform
operation but the problem would seem to be that the functor does not know the index of the element it is operating on.
I thought that something like:
elements
= boost::fusion::transform(boost::fusion::zip(ranges, indices), getValue);
might work if I could somehow make Fusion sequence indices
containing int 0...N
So can someone help me make an ascending sequence, or find a better way to achieve my goal? Many thanks.
You can obtain a sequence of ascending non-type template parameters with boost::mpl::range_c. You will need to copy this sequence to another mpl::sequence as ranges don't fulfil all necessary concept requirements to be used with transform
. The sequence can be adapted with fusion
.
精彩评论