[gcc r16-2096] libstdc++: Implement __mdspan::__size.
Tomasz Kaminski
tkaminsk@gcc.gnu.org
Tue Jul 8 11:52:47 GMT 2025
https://gcc.gnu.org/g:aa961cae42e23461887a6cf38aa47413b8425243
commit r16-2096-gaa961cae42e23461887a6cf38aa47413b8425243
Author: Luc Grosheintz <luc.grosheintz@gmail.com>
Date: Fri Jul 4 10:29:46 2025 +0200
libstdc++: Implement __mdspan::__size.
The current code uses __mdspan::__fwd_prod(__exts, __rank) to express
computing the size of an extent. This commit adds an function __mdspan::
__size(__exts) to express the idea more directly.
libstdc++-v3/ChangeLog:
* include/std/mdspan (__mdspan::__size): New function.
Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Luc Grosheintz <luc.grosheintz@gmail.com>
Diff:
---
libstdc++-v3/include/std/mdspan | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/std/mdspan b/libstdc++-v3/include/std/mdspan
index d97fa22e4f03..b0d8088bb777 100644
--- a/libstdc++-v3/include/std/mdspan
+++ b/libstdc++-v3/include/std/mdspan
@@ -398,6 +398,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__rev_prod(const _Extents& __exts, size_t __r) noexcept
{ return __exts_prod(__exts, __r + 1, __exts.rank()); }
+ template<typename _Extents>
+ constexpr typename _Extents::index_type
+ __size(const _Extents& __exts) noexcept
+ { return __fwd_prod(__exts, __exts.rank()); }
+
template<typename _IndexType, size_t... _Counts>
auto __build_dextents_type(integer_sequence<size_t, _Counts...>)
-> extents<_IndexType, ((void) _Counts, dynamic_extent)...>;
@@ -591,7 +596,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr index_type
required_span_size() const noexcept
- { return __mdspan::__fwd_prod(_M_extents, extents_type::rank()); }
+ { return __mdspan::__size(_M_extents); }
template<__mdspan::__valid_index_type<index_type>... _Indices>
requires (sizeof...(_Indices) == extents_type::rank())
@@ -730,7 +735,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr index_type
required_span_size() const noexcept
- { return __mdspan::__fwd_prod(_M_extents, extents_type::rank()); }
+ { return __mdspan::__size(_M_extents); }
template<__mdspan::__valid_index_type<index_type>... _Indices>
requires (sizeof...(_Indices) == extents_type::rank())
@@ -986,8 +991,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if constexpr (!is_always_exhaustive())
{
- constexpr auto __rank = extents_type::rank();
- auto __size = __mdspan::__fwd_prod(_M_extents, __rank);
+ auto __size = __mdspan::__size(_M_extents);
if(__size > 0)
return __size == required_span_size();
}
More information about the Libstdc++-cvs
mailing list