]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement submdspan_mapping for layout_right. [PR110352]
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Mon, 8 Dec 2025 20:23:42 +0000 (21:23 +0100)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 9 Dec 2025 12:46:36 +0000 (13:46 +0100)
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 <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
libstdc++-v3/include/std/mdspan
libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_mapping.cc
libstdc++-v3/testsuite/23_containers/mdspan/submdspan/submdspan_neg.cc

index 0d477b7fa9e83d91b9bba43958a6af4fafaa98fd..5ee29e135875b8c54fcd21580aea52cb0962d64e 100644 (file)
@@ -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<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);
+           if constexpr (!__mdspan::__all_static(__sta_exts))
+             return dynamic_extent;
+           else
+             return __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)
+         {
+           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<typename _Mapping>
       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<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
+
        [[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 (file)
index 0000000..2557072
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do run { target c++26 } }
+#include "testcases.h"
+
+int
+main()
+{
+  test_all<std::layout_right>();
+  return 0;
+}
index a37d3cd588f6d26b5c05030547eb88d554f28883..cc832cdb415ada7663596fb94c1ece72cd0096c0 100644 (file)
@@ -129,8 +129,14 @@ main()
   test_layout_unpadded_return_types<std::layout_left>();
   static_assert(test_layout_unpadded_return_types<std::layout_left>());
 
+  test_layout_unpadded_return_types<std::layout_right>();
+  static_assert(test_layout_unpadded_return_types<std::layout_right>());
+
   test_layout_unpadded_padding_value<std::layout_left>();
   static_assert(test_layout_unpadded_padding_value<std::layout_left>());
+
+  test_layout_unpadded_padding_value<std::layout_right>();
+  static_assert(test_layout_unpadded_padding_value<std::layout_right>());
   return 0;
 }
 
index 1fc10a832ebbffc0a15bbf03f8c53dabd1b4a882..15b9b2e71ec11e056a4ec8b89591c94d9bd1a0ce 100644 (file)
@@ -24,6 +24,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_int_under<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_int_under<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -33,6 +34,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_int_over<std::layout_left>());    // { dg-error "expansion of" }
+static_assert(test_int_over<std::layout_right>());   // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -42,6 +44,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_tuple_under<std::layout_left>());     // { dg-error "expansion of" }
+static_assert(test_tuple_under<std::layout_right>());    // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -51,6 +54,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_tuple_reversed<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_tuple_reversed<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -60,6 +64,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_tuple_over<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_tuple_over<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -69,6 +74,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_strided_slice_zero<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_strided_slice_zero<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -78,6 +84,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_strided_slice_offset_under<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_strided_slice_offset_under<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -87,6 +94,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_strided_slice_offset_over<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_strided_slice_offset_over<std::layout_right>());  // { dg-error "expansion of" }
 
 template<typename Layout>
   constexpr bool
@@ -96,6 +104,7 @@ template<typename Layout>
     return true;
   }
 static_assert(test_strided_slice_extent_over<std::layout_left>());   // { dg-error "expansion of" }
+static_assert(test_strided_slice_extent_over<std::layout_right>());  // { dg-error "expansion of" }
 
 // { dg-prune-output "static assertion failed" }
 // { dg-prune-output "__glibcxx_assert_fail" }