[PATCH v5 3/7] libstdc++: Implement submdspan_mapping for layout_right. [PR110352]
Jonathan Wakely
jwakely@redhat.com
Tue Dec 9 11:28:57 GMT 2025
On Mon, 8 Dec 2025 at 22:26, Luc Grosheintz <luc.grosheintz@gmail.com> wrote:
>
> Adds submdspan_mapping for layout_right as described in P3663.
>
> PR libstdc++/110352
>
> libstdc++-v3/ChangeLog:
>
> * include/std/mdspan (layout_right::mapping::submdspan_mapping): New
> friend function.
The new _SubMdspanMapping<__right> specialization isn't mentioned in
the changelog.
OK with that added.
> * 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.
>
> Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
> ---
> 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(+)
> create mode 100644 libstdc++-v3/testsuite/23_containers/mdspan/submdspan/selections/right.cc
>
> diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
> index 4c004335289..c962d0e0cd3 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 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<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 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<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 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<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" }
> --
> 2.52.0
>
More information about the Libstdc++
mailing list