2

As C++23 supports multidimensional subscript operator(eg. a[1, 2, 3] and mdspan, is there native support for storing an multidimensional index as an object and used multiple times?

One example could be

// 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]);

Is there anything we would get from the mdspan library that achieve this? I feel this is actually something handy when doing operations above, but seems like we need to implement ourselves.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
user122049
  • 397
  • 1
  • 11
  • AFAIK there is no such type, but it should not be difficult to write a function that uses the values from a tuple to access a multidim subscript. – gerum Jan 13 '23 at 12:35
  • 4
    `std::mdspan`'s [`operator[]`](http://eel.is/c++draft/mdspan.mdspan.members#lib:operator%5b%5d,mdspan_) can take a `std::span` or `std::array`, but of course not all multidimensional array types may support this. – cpplearner Jan 13 '23 at 13:39

0 Answers0