存储可在 operator[] 中提供的多维索引的对象

Object that stores multidimensional index that can be supplied in operator[]

提问人:user122049 提问时间:1/13/2023 最后编辑:einpoklumuser122049 更新时间:3/19/2023 访问量:97

问:

由于 C++23 支持多维下标运算符(例如。 并且,是否本机支持将多维索引存储为对象并多次使用?a[1, 2, 3]mdspan

一个例子可能是

// not storing as object {int a; double b;} due to layout considerations
// maybe we want contiguous accessing a/b individually to be fast but there are
// slow operations using both
std::array<std::array<std::array<int, L>, M>, N> a;
std::array<std::array<std::array<double,L>, M>, N> b;
// Index is conjured up
Index idx{3, 5, 2};
doSomething(a[idx], b[idx]);

我们能从mdspan库中得到什么来实现这一点吗?我觉得在进行上述操作时,这实际上是方便的,但似乎我们需要自己实现。

C++ C++23 MDSPAN

评论

0赞 gerum 1/13/2023
AFAIK 没有这样的类型,但编写一个使用元组中的值来访问多元下标的函数应该不难。
4赞 cpplearner 1/13/2023
std::mdspan运算符[]可以采用或,但当然不是所有的多维数组类型都支持这一点。std::spanstd::array

答: 暂无答案