On Mon, Jul 21, 2025 at 5:51 PM Luc Grosheintz <luc.groshei...@gmail.com>
wrote:

> This commit implements the C++26 feature std::dims described in P2389R2.
> It sets the feature testing macro to 202406 and adds tests.
>
> Also fixes the test mdspan/version.cc
>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/version.def (mdspan): Set value for C++26.
>         * include/bits/version.h: Regenerate.
>         * include/std/mdspan (dims): Add.
>         * src/c++23/std.cc.in (dims): Add.
>         * testsuite/23_containers/mdspan/extents/misc.cc: Add tests.
>         * testsuite/23_containers/mdspan/version.cc: Update test.
>
> Signed-off-by: Luc Grosheintz <luc.groshei...@gmail.com>
> ---
>
LGTM.

As you are contributing actively, I will add a bit of current context.
Jonathan is currently taking well-deserved time off, with limited capability
to approve/review the patches, so some of these patches may linger for a
bit.
I may also have less time for reviewing in the upcoming weeks.

However, we have discussed internally, and patches adding a test that test
existing
behavior may be merged by us, after review.

Given above, this may be a good time to look into optimizing/code-gen for
the mapping
functions.




>  libstdc++-v3/include/bits/version.def                 |  4 ++++
>  libstdc++-v3/include/bits/version.h                   |  7 ++++++-
>  libstdc++-v3/include/std/mdspan                       |  5 +++++
>  libstdc++-v3/src/c++23/std.cc.in                      |  3 +++
>  .../testsuite/23_containers/mdspan/extents/misc.cc    |  7 +++++++
>  .../testsuite/23_containers/mdspan/version.cc         | 11 +++++++----
>  6 files changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/version.def
> b/libstdc++-v3/include/bits/version.def
> index dbe2cb8f175..e9830d9d685 100644
> --- a/libstdc++-v3/include/bits/version.def
> +++ b/libstdc++-v3/include/bits/version.def
> @@ -1007,6 +1007,10 @@ ftms = {
>
>  ftms = {
>    name = mdspan;
> +  values = {
> +    v = 202406;
> +    cxxmin = 26;
> +  };
>    values = {
>      v = 202207;
>      cxxmin = 23;
> diff --git a/libstdc++-v3/include/bits/version.h
> b/libstdc++-v3/include/bits/version.h
> index 7bb6016df68..59b0cfa1f92 100644
> --- a/libstdc++-v3/include/bits/version.h
> +++ b/libstdc++-v3/include/bits/version.h
> @@ -1125,7 +1125,12 @@
>  #undef __glibcxx_want_span
>
>  #if !defined(__cpp_lib_mdspan)
> -# if (__cplusplus >= 202100L)
> +# if (__cplusplus >  202302L)
> +#  define __glibcxx_mdspan 202406L
> +#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_mdspan)
> +#   define __cpp_lib_mdspan 202406L
> +#  endif
> +# elif (__cplusplus >= 202100L)
>  #  define __glibcxx_mdspan 202207L
>  #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_mdspan)
>  #   define __cpp_lib_mdspan 202207L
> diff --git a/libstdc++-v3/include/std/mdspan
> b/libstdc++-v3/include/std/mdspan
> index 271fdb5d8c7..9afb9304fb5 100644
> --- a/libstdc++-v3/include/std/mdspan
> +++ b/libstdc++-v3/include/std/mdspan
> @@ -414,6 +414,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>      using dextents = decltype(__mdspan::__build_dextents_type<_IndexType>(
>         make_index_sequence<_Rank>()));
>
> +#if __glibcxx_mdspan >= 202406L
> +  template<size_t _Rank, typename _IndexType = size_t>
> +    using dims = dextents<_IndexType, _Rank>;
> +#endif
> +
>    template<typename... _Integrals>
>      requires (is_convertible_v<_Integrals, size_t> && ...)
>      explicit extents(_Integrals...) ->
> diff --git a/libstdc++-v3/src/c++23/std.cc.in b/libstdc++-v3/src/c++23/
> std.cc.in
> index 9301ed90c00..6d7f3fda060 100644
> --- a/libstdc++-v3/src/c++23/std.cc.in
> +++ b/libstdc++-v3/src/c++23/std.cc.in
> @@ -1851,6 +1851,9 @@ export namespace std
>  {
>    using std::extents;
>    using std::dextents;
> +#if __glibcxx_mdspan >= 202406L
> +  using std::dims;
> +#endif
>    using std::layout_left;
>    using std::layout_right;
>    using std::layout_stride;
> diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
> b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
> index bca8901685d..8a43a682004 100644
> --- a/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
> +++ b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc
> @@ -159,6 +159,13 @@ static_assert(std::extents<int, 1,
> dyn>::static_extent(1) == dyn);
>  static_assert(std::extents<int, dyn, dyn>::static_extent(0) == dyn);
>  static_assert(std::extents<int, dyn, dyn>::static_extent(1) == dyn);
>
> +// dims
> +#if __glibcxx_mdspan >= 202406L
> +static_assert(std::is_same_v<std::dims<0>, std::dextents<size_t, 0>>);
> +static_assert(std::is_same_v<std::dims<3>, std::dextents<size_t, 3>>);
> +static_assert(std::is_same_v<std::dims<3, int>, std::dextents<int, 3>>);
> +#endif
> +
>  // extent
>  template<typename Extent>
>    constexpr void
> diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/version.cc
> b/libstdc++-v3/testsuite/23_containers/mdspan/version.cc
> index 106ee4010ee..752060262a0 100644
> --- a/libstdc++-v3/testsuite/23_containers/mdspan/version.cc
> +++ b/libstdc++-v3/testsuite/23_containers/mdspan/version.cc
> @@ -1,9 +1,12 @@
> -// { dg-do compile { target c++23 } }
> +// { dg-do preprocess { target c++23 } }
> +// { dg-add-options no_pch }
> +
>  #include <mdspan>
>
>  #ifndef __cpp_lib_mdspan
>  #error "Feature test macro __cpp_lib_mdspan is missing for <mdspan>"
> -#if __cpp_lib_mdspan < 202207
> -#error "Feature test macro __cpp_lib_mdspan has the wrong value"
> -#endif
> +#elif __cplusplus <= 202302L && __cpp_lib_mdspan != 202207L
> +#error "Feature test macro __cpp_lib_mdspan has the wrong value for C++23"
> +#elif __cplusplus > 202302L && __cpp_lib_mdspan != 202406L
> +#error "Feature test macro __cpp_lib_mdspan has the wrong value for C++26"
>  #endif
> --
> 2.50.0
>
>

Reply via email to