请找一个更好的标题
如果您了解Mathematica,我想做一些与此相关的事情:
m = {{a, b, c}, {d, e}, {f, g, h}};
m[[All, 2]] (* returns: {b, e, g} *)
假设我有一些物体,它们排列在一个N维网格上,比方说3D并调用尺寸x,y,z
。此外,x,y,z
也是对象的属性,每个(x,y,z)
与对象之间存在1-1关系。
现在我想在一个方向上迭代一个容器,用迭代器接口保持另外两个属性,例如:
Container<MyObject> container;
...
container::iterator it1 = container.begin(undefined, 1, 2);
container::iterator it2 = container.end(undefined, 1, 2);
// now the range [it1, it2] contains all the objects with y=1 and z=2
// ordered by x
我查看了boost::multi_index_container
,但似乎您无法在我的示例中修复y
和z
。
我不想重新发明轮子,这是一个很好的解决方案吗?
x,y,z
是通用类型(通常为int
,string
或enum
)w
)MyObject
对象不可排序(是的,我可以使用x,y,z
对其进行排序)