The repo of the exciting mdspan
, a multi-dimensional analogue of std::span
suggested for the C++ standard libraries, now also contains a reference implementation of the closely-related mdarray
, which unlike mdspan
owns its data.
But whereas the submdspan
function can produce a subset of an mdspan
, I can't find an analogue for mdarray
. What I was expecting was a function that behaves exactly the same as submdspan
and returns an mdspan
, but which operates on an mdarray
.
Is this planned but not implemented yet? If not, why not?
Edit:
I've temporarily solved it with a home-brew solution in the form of an overload of submdspan
that takes an mdarray
, then creates a temporary mdspan
that maps to the entire mdarray
, and calls submdspan
on that.
It does the job for now! But I'm not confident this covers every conceivable mdarray
, as there is almost no documentation at the moment. Would still love an answer to the original question.
template <class ElementType, class Extents, class LayoutPolicy, class... SliceSpecs>
auto submdspan(
mdarray<ElementType, Extents, LayoutPolicy> &arr,
SliceSpecs... slices)
{
return submdspan(
mdspan<ElementType, Extents, LayoutPolicy>(arr.data(), arr.mapping()),
slices...);
}
Just randomly ran across this: since I am the primary author/maintainer on all involved things (mdspan
, mdarray
, submdspan
and the reference implementation) yeah we can add that. And the way I would do that is actually calling the "to_mdspan" function of the mdarray
, and call submdspan on that:
auto sub = submdspan(mda.to_mdspan(), slice_specifiers...);
In order for the two proposals to be independent I will keep that apart for now (unless LEWG tells me otherwise) and write a follow up paper which simply adds an overload to submdspan
which does the above to forward to the overload taking an mdspan
.
But generally: you can just open an issue on the repo to ask about proposal issues.