From: Luc Grosheintz Date: Mon, 8 Dec 2025 20:23:45 +0000 (+0100) Subject: libstdc++: Implement submdspan_mapping for layout_right_padded. [PR110352] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5d72af36d406b55f31e709f01b5fc184019ff26;p=thirdparty%2Fgcc.git libstdc++: Implement submdspan_mapping for layout_right_padded. [PR110352] Implements submdspan for layout_right_padded as described in P3663. PR libstdc++/110352 libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::_SubMdspanMapping<_LayoutSide::__right, true>): Define. (layout_right_padded::submdspan_mapping): New friend function. * testsuite/23_containers/mdspan/submdspan/selections/right_padded.cc: Instantiate tests for layout_right_padded. * testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc: Ditto. Reviewed-by: Tomasz KamiƄski Signed-off-by: Luc Grosheintz --- diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan index 12413a0662f..dc0aa4f9584 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -1374,6 +1374,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; + template<> + struct _SubMdspanMapping<_LayoutSide::__right, true> + { + using _Layout = layout_right; + template using _PaddedLayout = layout_right_padded<_Pad>; + + template + static consteval size_t + _S_pad() + { + using _Extents = typename _Mapping::extents_type; + constexpr auto __rank = _Extents::rank(); + constexpr auto __sta_exts + = __mdspan::__static_extents<_Extents>(_Us + 1, __rank - 1); + constexpr auto __sta_padstride + = __mdspan::__get_static_stride<_Mapping>(); + if constexpr (__sta_padstride == dynamic_extent + || !__mdspan::__all_static(__sta_exts)) + return dynamic_extent; + else + return __sta_padstride * __mdspan::__fwd_prod(__sta_exts); + } + + template + static consteval bool + _S_is_unpadded_submdspan(span __slice_kinds, + size_t __sub_rank) + { + if (__sub_rank == 1) + return __slice_kinds[_Nm - 1] == _SliceKind::__unit_strided_slice + || __slice_kinds[_Nm - 1] == _SliceKind::__full; + else + return false; + } + }; + + template constexpr auto __submdspan_mapping_impl(const _Mapping& __mapping) @@ -2775,6 +2812,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator==(const mapping& __self, const _RightPaddedMapping& __other) noexcept { return __self._M_storage._M_equal(__other); } + +#if __glibcxx_submdspan + private: + template + requires (extents_type::rank() == sizeof...(_Slices)) + friend constexpr auto + submdspan_mapping(const mapping& __mapping, _Slices... __slices) + { return __mdspan::__submdspan_mapping_impl(__mapping, __slices...); } +#endif // __glibcxx_submdspan }; #endif // __glibcxx_padded_layouts diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right_padded.cc b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right_padded.cc new file mode 100644 index 00000000000..24ed6cb7d62 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right_padded.cc @@ -0,0 +1,12 @@ +// { dg-do run { target c++26 } } +// { dg-timeout-factor 2 } +#include "testcases.h" + +int +main() +{ + test_all>(); + test_all>(); + 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 50836968a06..efd71d10f9d 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc @@ -290,6 +290,10 @@ main() test_return_types_padded_all>(); test_return_types_padded_all>(); + test_return_types_padded_all>(); + test_return_types_padded_all>(); + test_return_types_padded_all>(); + test_layout_stride_return_types(); static_assert(test_layout_stride_return_types()); return 0;