https://gcc.gnu.org/g:f5d72af36d406b55f31e709f01b5fc184019ff26

commit r16-5998-gf5d72af36d406b55f31e709f01b5fc184019ff26
Author: Luc Grosheintz <[email protected]>
Date:   Mon Dec 8 21:23:45 2025 +0100

    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 <[email protected]>
    Signed-off-by: Luc Grosheintz <[email protected]>

Diff:
---
 libstdc++-v3/include/std/mdspan                    | 46 ++++++++++++++++++++++
 .../mdspan/submdspan/selections/right_padded.cc    | 12 ++++++
 .../mdspan/submdspan/submdspan_mapping.cc          |  4 ++
 3 files changed, 62 insertions(+)

diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index 12413a0662fb..dc0aa4f9584f 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<size_t _Pad> using _PaddedLayout = layout_right_padded<_Pad>;
+
+       template<typename _Mapping, size_t _Us>
+         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<size_t _Nm>
+         static consteval bool
+         _S_is_unpadded_submdspan(span<const _SliceKind, _Nm> __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<typename _Mapping>
       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<typename... _Slices>
+         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 000000000000..24ed6cb7d62f
--- /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<std::layout_right_padded<1>>();
+  test_all<std::layout_right_padded<8>>();
+  test_all<std::layout_right_padded<dyn>>();
+  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 50836968a06b..efd71d10f9d9 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<std::layout_left_padded<2>>();
   test_return_types_padded_all<std::layout_left_padded<dyn>>();
 
+  test_return_types_padded_all<std::layout_right_padded<1>>();
+  test_return_types_padded_all<std::layout_right_padded<2>>();
+  test_return_types_padded_all<std::layout_right_padded<dyn>>();
+
   test_layout_stride_return_types();
   static_assert(test_layout_stride_return_types());
   return 0;

Reply via email to