diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index 5ee29e135875..6386a26e392d 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -1928,6 +1928,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } private: +#if __glibcxx_submdspan + template + requires (extents_type::rank() == sizeof...(_Slices)) + friend constexpr auto + submdspan_mapping(const mapping& __mapping, _Slices... __slices) + { + if constexpr (sizeof...(_Slices) == 0) + return submdspan_mapping_result{__mapping, 0}; + else + { + auto __offset = __mdspan::__suboffset(__mapping, __slices...); + auto __sub_exts = __mdspan::__subextents(__mapping.extents(), __slices...); + auto __sub_strides + = __mdspan::__substrides(__mapping, __slices...); + return submdspan_mapping_result{ + layout_stride::mapping(__sub_exts, __sub_strides), __offset}; + } + } +#endif + using _Strides = typename __array_traits::_Type; [[no_unique_address]] extents_type _M_extents; diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/stride.cc b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/stride.cc new file mode 100644 index 000000000000..19451d7f954e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/stride.cc @@ -0,0 +1,9 @@ +// { dg-do run { target c++26 } } +#include "testcases.h" + +int +main() +{ + test_all(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc index cc832cdb415a..cf6167dc3b0f 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc @@ -123,6 +123,21 @@ template return true; } +constexpr bool +test_layout_stride_return_types() +{ + auto exts = std::extents(3, 5); + auto m = std::layout_stride::mapping(exts, std::array{2, 12}); + + using index_type = decltype(exts)::index_type; + auto s1 = std::strided_slice{index_type(2), index_type(2), + std::cw}; + auto result = submdspan_mapping(m, index_type(1), s1); + using layout_type = decltype(result.mapping)::layout_type; + static_assert(std::same_as); + return true; +} + int main() { @@ -132,6 +147,9 @@ main() test_layout_unpadded_return_types(); static_assert(test_layout_unpadded_return_types()); + test_layout_stride_return_types(); + static_assert(test_layout_stride_return_types()); + test_layout_unpadded_padding_value(); static_assert(test_layout_unpadded_padding_value()); diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc index 15b9b2e71ec1..39eb18cb03df 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc @@ -25,6 +25,7 @@ template } static_assert(test_int_under()); // { dg-error "expansion of" } static_assert(test_int_under()); // { dg-error "expansion of" } +static_assert(test_int_under()); // { dg-error "expansion of" } template constexpr bool @@ -35,6 +36,7 @@ template } static_assert(test_int_over()); // { dg-error "expansion of" } static_assert(test_int_over()); // { dg-error "expansion of" } +static_assert(test_int_over()); // { dg-error "expansion of" } template constexpr bool @@ -45,6 +47,7 @@ template } static_assert(test_tuple_under()); // { dg-error "expansion of" } static_assert(test_tuple_under()); // { dg-error "expansion of" } +static_assert(test_tuple_under()); // { dg-error "expansion of" } template constexpr bool @@ -55,6 +58,7 @@ template } static_assert(test_tuple_reversed()); // { dg-error "expansion of" } static_assert(test_tuple_reversed()); // { dg-error "expansion of" } +static_assert(test_tuple_reversed()); // { dg-error "expansion of" } template constexpr bool @@ -65,6 +69,7 @@ template } static_assert(test_tuple_over()); // { dg-error "expansion of" } static_assert(test_tuple_over()); // { dg-error "expansion of" } +static_assert(test_tuple_over()); // { dg-error "expansion of" } template constexpr bool @@ -75,6 +80,7 @@ template } static_assert(test_strided_slice_zero()); // { dg-error "expansion of" } static_assert(test_strided_slice_zero()); // { dg-error "expansion of" } +static_assert(test_strided_slice_zero()); // { dg-error "expansion of" } template constexpr bool @@ -85,6 +91,7 @@ template } static_assert(test_strided_slice_offset_under()); // { dg-error "expansion of" } static_assert(test_strided_slice_offset_under()); // { dg-error "expansion of" } +static_assert(test_strided_slice_offset_under()); // { dg-error "expansion of" } template constexpr bool @@ -95,6 +102,7 @@ template } static_assert(test_strided_slice_offset_over()); // { dg-error "expansion of" } static_assert(test_strided_slice_offset_over()); // { dg-error "expansion of" } +static_assert(test_strided_slice_offset_over()); // { dg-error "expansion of" } template constexpr bool @@ -105,6 +113,7 @@ template } static_assert(test_strided_slice_extent_over()); // { dg-error "expansion of" } static_assert(test_strided_slice_extent_over()); // { dg-error "expansion of" } +static_assert(test_strided_slice_extent_over()); // { dg-error "expansion of" } // { dg-prune-output "static assertion failed" } // { dg-prune-output "__glibcxx_assert_fail" }