From: Luc Grosheintz Date: Mon, 8 Dec 2025 20:23:42 +0000 (+0100) Subject: libstdc++: Implement submdspan_mapping for layout_right. [PR110352] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1c5ada671dccb556d636e9c968cfaef176dbb5c;p=thirdparty%2Fgcc.git libstdc++: Implement submdspan_mapping for layout_right. [PR110352] Adds submdspan_mapping for layout_right as described in P3663. PR libstdc++/110352 libstdc++-v3/ChangeLog: * include/std/mdspan (__mdspan::_SubMdspanMapping<_LayoutSide::__right>): Define. (layout_right::mapping::submdspan_mapping): New friend function. * testsuite/23_containers/mdspan/submdspan/selections/right.cc: Instantiate tests for layout_right. * testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc: Ditto. * testsuite/23_containers/mdspan/submdspan/submdspan_neg.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 0d477b7fa9e..5ee29e13587 100644 --- a/libstdc++-v3/include/std/mdspan +++ b/libstdc++-v3/include/std/mdspan @@ -1303,6 +1303,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { return __mdspan::__is_block(__slice_kinds, __sub_rank); } }; + template<> + struct _SubMdspanMapping<_LayoutSide::__right> + { + 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); + if constexpr (!__mdspan::__all_static(__sta_exts)) + return dynamic_extent; + else + return __fwd_prod(__sta_exts); + } + + template + static consteval bool + _S_is_unpadded_submdspan(span __slice_kinds, + size_t __sub_rank) + { + auto __rev_slice_kinds = array<_SliceKind, _Nm>{}; + for(size_t __i = 0; __i < _Nm; ++__i) + __rev_slice_kinds[__i] = __slice_kinds[_Nm - 1 - __i]; + return __mdspan::__is_block(span(__rev_slice_kinds), __sub_rank); + } + }; + template constexpr auto __submdspan_mapping_impl(const _Mapping& __mapping) @@ -1678,6 +1710,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_assert(__mdspan::__is_representable_extents(_M_extents)); } +#if __glibcxx_submdspan + 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 + [[no_unique_address]] extents_type _M_extents{}; }; diff --git a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right.cc b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right.cc new file mode 100644 index 00000000000..25570721072 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right.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 a37d3cd588f..cc832cdb415 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc @@ -129,8 +129,14 @@ main() test_layout_unpadded_return_types(); static_assert(test_layout_unpadded_return_types()); + test_layout_unpadded_return_types(); + static_assert(test_layout_unpadded_return_types()); + test_layout_unpadded_padding_value(); static_assert(test_layout_unpadded_padding_value()); + + test_layout_unpadded_padding_value(); + static_assert(test_layout_unpadded_padding_value()); return 0; } 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 1fc10a832eb..15b9b2e71ec 100644 --- a/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc @@ -24,6 +24,7 @@ template return true; } static_assert(test_int_under()); // { dg-error "expansion of" } +static_assert(test_int_under()); // { dg-error "expansion of" } template constexpr bool @@ -33,6 +34,7 @@ template return true; } static_assert(test_int_over()); // { dg-error "expansion of" } +static_assert(test_int_over()); // { dg-error "expansion of" } template constexpr bool @@ -42,6 +44,7 @@ template return true; } static_assert(test_tuple_under()); // { dg-error "expansion of" } +static_assert(test_tuple_under()); // { dg-error "expansion of" } template constexpr bool @@ -51,6 +54,7 @@ template return true; } static_assert(test_tuple_reversed()); // { dg-error "expansion of" } +static_assert(test_tuple_reversed()); // { dg-error "expansion of" } template constexpr bool @@ -60,6 +64,7 @@ template return true; } static_assert(test_tuple_over()); // { dg-error "expansion of" } +static_assert(test_tuple_over()); // { dg-error "expansion of" } template constexpr bool @@ -69,6 +74,7 @@ template return true; } static_assert(test_strided_slice_zero()); // { dg-error "expansion of" } +static_assert(test_strided_slice_zero()); // { dg-error "expansion of" } template constexpr bool @@ -78,6 +84,7 @@ template return true; } 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 @@ -87,6 +94,7 @@ template return true; } 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 @@ -96,6 +104,7 @@ template return true; } 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" }