So, I decided I want to use an mdspan
rather than a combination of plain span + element access function. But - one obvious thing I want to do with my mdspan is iterate its elements. This is how I would do it with a 1D span:
std::vector vec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
auto sp = std::span(vec.data(), 12);
for (auto x : sp) {
std::cout << x << ' ';
}
std::cout << '\n';
... but not for mdspan
's (using the Kokkos implementation):
std::vector vec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
auto ms = std::mdspan(vec.data(), 12);
for (auto x : ms) {
std::cout << x << ' ';
}
std::cout << '\n';
Trying the above in GodBolt (with GCC trunk), I get:
<source>:10:19: error: 'begin' was not declared in this scope
10 | for (auto x : ms) {
| ^~
so, it seems mdspans are not ranges - even if they're one-dimensional (and I was even hoping to iterate 2D or 3D spans...). How come? And how do I iterate them?
mdspan
. Where's the consistency? It was initiated as a view; Now just doesn't satisfy the requirements of a view. – Schoolboy