]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Implement __mdspan::__size.
authorLuc Grosheintz <luc.grosheintz@gmail.com>
Fri, 4 Jul 2025 08:29:46 +0000 (10:29 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 8 Jul 2025 11:48:56 +0000 (13:48 +0200)
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>
libstdc++-v3/include/std/mdspan

index d97fa22e4f036910f17b623d2220b2ab438576cb..b0d8088bb7774c4b964c4af2f319063771cdf18e 100644 (file)
@@ -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();
          }