运行时和融合序列之间的交互
进一步我的问题 C++ Boost.Range 元组 - 获取元素类型的元组?
我有以下内容:
TupleOfRanges ranges;
TupleOfElements elements;
std::vector<int> offsets;
所有容器(元和运行时)的大小均为N
。我想编写执行以下操作的代码:
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]);
我尝试使用 Fusion 的 transform
操作编写此代码,但问题似乎是函子不知道它正在操作的元素的索引。
我认为这样的事情
elements
= boost::fusion::transform(boost::fusion::zip(ranges, indices), getValue);
可能会起作用:如果我能以某种方式使Fusion序列indices
包含int 0...N
那么有人可以帮助我制作一个升序序列,或者找到一个实现我的目标的更好方法?非常感谢。
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 transform
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 boost::mpl::range_c。您需要将此序列复制到另一个 mpl::sequence,因为范围不能满足与
transform
一起使用的所有必要概念要求。该序列可以通过fusion
进行调整。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 withfusion
.