This commit implements the C++26 feature std::dims, sets the feature testing macro to 202403 and adds tests.
libstdc++-v3/ChangeLog: * include/bits/version.def (mdspan): Set value for C++26. * include/bits/version.h: Regenerate. * include/std/mdspan (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> --- libstdc++-v3/include/bits/version.def | 4 ++++ libstdc++-v3/include/bits/version.h | 7 ++++++- libstdc++-v3/include/std/mdspan | 5 +++++ .../testsuite/23_containers/mdspan/extents/misc.cc | 7 +++++++ libstdc++-v3/testsuite/23_containers/mdspan/version.cc | 6 ++++-- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index cf0672b4822..f645bb3ed3b 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 = 202403; + cxxmin = 26; + }; values = { v = 202207; cxxmin = 23; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index c01ddf14dd5..fbdc9b65acf 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 202403L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_mdspan) +# define __cpp_lib_mdspan 202403L +# 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 b34116a85e6..ffbd1d9d542 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -412,6 +412,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using dextents = decltype(__mdspan::__build_dextents_type<_IndexType>( make_index_sequence<_Rank>())); +#if __glibcxx_mdspan >= 202403L + 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/testsuite/23_containers/mdspan/extents/misc.cc b/libstdc++-v3/testsuite/23_containers/mdspan/extents/misc.cc index bca8901685d..933a77aab79 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 >= 202403L +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..aa3767bd2c5 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/version.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/version.cc @@ -3,7 +3,9 @@ #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" +#if __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 != 202403L +#error "Feature test macro __cpp_lib_mdspan has the wrong value for C++26" #endif #endif -- 2.50.0