C++容器问题
我一直在寻找一些合适的二维元素容器。我想要的是能够使用例如 BOOST_FOREACH
迭代容器的每个元素,并且我还希望能够构建容器的子视图(切片/子范围),并且可能进行迭代也通过他们。
现在我正在使用 boost::numeric::ublas::matrix 来实现这些目的,但是,它对我来说看起来不是一个好的解决方案,因为,它是一个 BLAS 矩阵,尽管它作为普通的 2d 元素容器表现得非常好(自定义无界
/ 有界
存储也非常好)。
另一种 boost
替代方案 boost::multi_array
很糟糕,因为您无法使用一个 BOOST_FOREACH
语句迭代每个元素,而且因为构造视图的语法极其混乱。
有其他选择吗?
谢谢。
I was looking for some suitable 2D element container. What I want is the ability to iterate through every element of the container using, for example BOOST_FOREACH
and I also would like to have an ability to construct subview (slices / subranges) of my container and, probably iterate through them too.
Right now I am using boost::numeric::ublas::matrix
for these purposes, but, well, it doesn't look as a good solution for me, because, well, it's a BLAS matrix, although it behaves very well as a plain 2d element container (custom unbounded
/ bounded
storages are also very sweet).
Another boost
alternative, boost::multi_array
is bad, because you can't iterate through every element using one BOOST_FOREACH
statement and because constructing views has extremely obfuscated syntax.
Any alternatives?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我执行以下操作(数组类型是容器/迭代器范围概念):
但是,这不适用于切片:最好的解决方案是为它们编写一个迭代器。
以下是使用
multi_array
提供自定义类存储的示例。也许你也可以这样做:
I do the following (array type is container/iterator range concept):
However, this will not work for slices: your best solution is to write an iterator for them.
Here is an example of using
multi_array
to provide storage of a custom class.Perhaps you could do the same:
定义您自己的类型(简单),给它一个迭代器和 const_interator(简单),BOOST_FOREACH 将使用它。
http://beta.boost.org/doc/libs/ 1_39_0/doc/html/foreach.html
Define your own type (trivial), give it an iterator and const_interator (trivial), and BOOST_FOREACH will work with it.
http://beta.boost.org/doc/libs/1_39_0/doc/html/foreach.html