1. Background
[P0009R18] added
, a non-owning multidimensional span abstraction
to the C++ Standard Library.
It is excellent and flexible, allowing users to customize customize data
layout, access method, and index type.
However, this flexibility often comes with verbosity.
The length of each dimension (the extent) of an
are represented by an
object, and each extent may be expressed either statically or
dynamically:
// All static. mdspan < int , 64 , 64 , 64 > a ( d ); // All dynamic. mdspan < int , dynamic_extent , dynamic_extent , dynamic_extent > a ( d , 64 , 64 , 64 ); // Mixed static and dynamic. mdspan < int , 64 , dynamic_extent , 64 > a ( d , 64 );
[P2299R3] sought to make
s easier to work with for one of the most
common cases - when all of your extents are dynamic.
It added deduction guides to make class template argument deduction (CTAD) work
for
and
.
mdspan a ( d , 64 , 64 ); // All dynamic.
However, CTAD does not help in all situations. If you are declaring a member of a class or a parameter to a function, you cannot use CTAD.
struct X { std :: mdspan < int , std :: dynamic_extent , std :: dynamic_extent , std :: dynamic_extent > a ; }; void f ( std :: mdspan < int , std :: dynamic_extent , std :: dynamic_extent , std :: dynamic_extent > a );
To simplify these cases, [P2299R3] also added
, a template alias
for an
with
dynamic extents.
template < std :: size_t N > using dextents = /* ... */ ; struct X { std :: mdspan < int , std :: dextents < 3 >> a ; }; void f ( mdspan < int , std :: dextents < 3 >> a );
2. Problem
Originally,
and
used a fixed index type (
).
However, the signedness and size of the index type can have an impact on
performance in certain cases.
So, [P2553R1] parameterized the index type used by
and
.
As a part of this change, an index type template parameter was added to
:
template < typename IndexType , std :: size_t Rank > using dextents = /* ... */
This change has made using
more verbose, which is unfortunate, as
the main purpose of
is to make common
usages as simple
as possible:
struct X { std :: mdspan < int , std :: dextents < std :: size_t , 3 >> a ; }; void f ( mdspan < int , std :: dextents < std :: size_t , 3 >> a );
Index type customization is an important feature for
to support, but it
is not something that most users will need to use or think about.
If they do need it, they can always use the more verbose
.
3. Proposed Changes
Remove the index type parameter from
and have it default to
.
MSVC’s STL and LLVM’s libc++ are already shipping
.
GCC’s libstdc++ is not shipping
yet.
So, modifying
would be a source-breaking change but would have no
ABI impact as
is a template alias.
Alternatively and more practically, we could leave
alone, but add a
new
template alias that does not have an index type parameter.