[gcc r16-5990] libstdc++: Implement submdspan_mapping for layout_right. [PR110352]
Tomasz Kaminski
tkaminsk@gcc.gnu.org
Tue Dec 9 12:47:32 GMT 2025
https://gcc.gnu.org/g:c1c5ada671dccb556d636e9c968cfaef176dbb5c
commit r16-5990-gc1c5ada671dccb556d636e9c968cfaef176dbb5c
Author: Luc Grosheintz <luc.grosheintz@gmail.com>
Date: Mon Dec 8 21:23:42 2025 +0100
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 <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Diff:
---
libstdc++-v3/include/std/mdspan | 40 ++++++++++++++++++++++
.../mdspan/submdspan/selections/right.cc | 9 +++++
.../mdspan/submdspan/submdspan_mapping.cc | 6 ++++
.../mdspan/submdspan/submdspan_neg.cc | 9 +++++
4 files changed, 64 insertions(+)
diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index 0d477b7fa9e8..5ee29e135875 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<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
index 000000000000..255707210721
--- /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<std::layout_right>();
+ 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 a37d3cd588f6..cc832cdb415a 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<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;
}
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 1fc10a832ebb..15b9b2e71ec1 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<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" }
More information about the Libstdc++-cvs
mailing list