[gcc r16-4091] libstdc++: Refactor __mdspan::__static_quotient.
Tomasz Kaminski
tkaminsk@gcc.gnu.org
Thu Sep 25 13:57:30 GMT 2025
https://gcc.gnu.org/g:5756d0b61317b28922e5c7a9ce30f0aca19b901d
commit r16-4091-g5756d0b61317b28922e5c7a9ce30f0aca19b901d
Author: Luc Grosheintz <luc.grosheintz@gmail.com>
Date: Tue Sep 23 15:10:04 2025 +0200
libstdc++: Refactor __mdspan::__static_quotient.
For padded layouts we want to check that the product of the
padded stride with the remaining extents is representable.
Creating a second overload, allows passing in subspans of the
static extents and retains the ergonomics for the common case
of passing in all static extents.
libstdc++-v3/ChangeLog:
* include/std/mdspan (__static_quotient): New overload.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Diff:
---
libstdc++-v3/include/std/mdspan | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index 01d3b2cb6b17..d9b5152b6938 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -597,13 +597,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __res;
}
- template<typename _Extents,
- typename _IndexType = typename _Extents::index_type>
+ template<typename _IndexType>
consteval _IndexType
- __static_quotient(_IndexType __nom = __gnu_cxx::__int_traits<_IndexType>
- ::__max)
+ __static_quotient(std::span<const size_t> __sta_exts,
+ _IndexType __nom = __gnu_cxx::__int_traits<_IndexType>::__max)
{
- std::span<const size_t> __sta_exts = __static_extents<_Extents>();
for (auto __factor : __sta_exts)
{
if (__factor != dynamic_extent)
@@ -614,6 +612,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __nom;
}
+ template<typename _Extents,
+ typename _IndexType = typename _Extents::index_type>
+ requires __is_extents<_Extents>
+ consteval _IndexType
+ __static_quotient(_IndexType __nom
+ = __gnu_cxx::__int_traits<_IndexType>::__max)
+ {
+ std::span<const size_t> __sta_exts = __static_extents<_Extents>();
+ return __static_quotient<_IndexType>(__sta_exts, __nom);
+ }
+
template<typename _Extents>
constexpr bool
__is_representable_extents(const _Extents& __exts) noexcept
More information about the Libstdc++-cvs
mailing list