|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4266" status="New"> |
| 5 | +<title>`layout_stride::mapping` should treat empty mappings as exhaustive</title> |
| 6 | +<section><sref ref="[mdspan.layout.stride]"/></section> |
| 7 | +<submitter>Tomasz Kamiński</submitter> |
| 8 | +<date>22 May 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Mapping over an empty multidimensional index space is always exhaustive according to the |
| 14 | +corresponding definitions from <sref ref="[mdspan.layout.reqmts]"/> p16. |
| 15 | +<p/> |
| 16 | +However, the current specification of `layout_stride::mapping` does not consider whether |
| 17 | +some of the empty multidimensional index spaces are unique or exhaustive. For illustration, |
| 18 | +the mapping with the following configuration is not considered exhaustive according to the |
| 19 | +current specification of <sref ref="[mdspan.layout.stride.obs]"/> bullet 5.2: |
| 20 | +</p> |
| 21 | +<blockquote><pre> |
| 22 | +extents: 2, 2, 0 |
| 23 | +strides: 2, 6, 20 |
| 24 | +</pre></blockquote> |
| 25 | +<p> |
| 26 | +This prevents the implementation from implementing `sm.is_exhaustive()` as |
| 27 | +<tt>sm.<i>fwd-prod-of-extents</i>(sm::extents_type::rank()) == sm.required_span_size()</tt>. |
| 28 | +For all mappings with size greater than zero, such an expression provides an answer consistent |
| 29 | +with the standard. However, it always returns `true` for an empty mapping, such as shown |
| 30 | +in the example. |
| 31 | +<p/> |
| 32 | +We should make such implementation conforming, and require `is_exhaustive()` to return |
| 33 | +`true` for empty mappings. |
| 34 | +<p/> |
| 35 | +For consistency, we could update `is_always_exhaustive()` to recognize mapping with |
| 36 | +`rank() == 0`, and one for which at least one of the static extents is equal to zero |
| 37 | +(i.e., they always represent a multidimensional index space). |
| 38 | +</p> |
| 39 | +</discussion> |
| 40 | + |
| 41 | +<resolution> |
| 42 | +<p> |
| 43 | +This wording is relative to <paper num="N5008"/>. |
| 44 | +</p> |
| 45 | +<ol> |
| 46 | + |
| 47 | +<li><p>Modify <sref ref="[mdspan.layout.stride.overview]"/> as indicated:</p> |
| 48 | + |
| 49 | +<blockquote> |
| 50 | +<pre> |
| 51 | +namespace std { |
| 52 | + template<class Extents> |
| 53 | + class layout_stride::mapping { |
| 54 | + […] |
| 55 | + static constexpr bool is_always_unique() noexcept { return true; } |
| 56 | + static constexpr bool is_always_exhaustive() noexcept<ins>;</ins><del>{ return false; }</del><ins>;</ins> |
| 57 | + static constexpr bool is_always_strided() noexcept { return true; } |
| 58 | + […] |
| 59 | + }; |
| 60 | +} |
| 61 | +</pre> |
| 62 | +</blockquote> |
| 63 | + |
| 64 | +</li> |
| 65 | + |
| 66 | +<li><p>Modify <sref ref="[mdspan.layout.stride.obs]"/> as indicated:</p> |
| 67 | + |
| 68 | +<blockquote> |
| 69 | +<p> |
| 70 | +[…] |
| 71 | +</p> |
| 72 | +<pre> |
| 73 | +<ins>static constexpr bool is_always_exhaustive() noexcept;</ins> |
| 74 | +</pre> |
| 75 | +<blockquote> |
| 76 | +<p> |
| 77 | +<ins>-?- <i>Returns</i>: `true` if <tt><i>rank_</i></tt> is `0` or if there is a rank index |
| 78 | +`r` of `extents()` such that `extents_type::static_extent(r)` is `0`, otherwise `false`.</ins> |
| 79 | +</p> |
| 80 | +</blockquote> |
| 81 | +<pre> |
| 82 | +constexpr bool is_exhaustive() const noexcept; |
| 83 | +</pre> |
| 84 | +<blockquote> |
| 85 | +<p> |
| 86 | +-5- <i>Returns</i>: |
| 87 | +</p> |
| 88 | +<ol style="list-style-type: none"> |
| 89 | +<li><p>(5.1) — `true` if <tt><i>rank_</i></tt> <ins>or the size of the multidimensional |
| 90 | +index space `m.extents()`</ins> is `0`.</p></li> |
| 91 | +<li><p>(5.2) — […]</p></li> |
| 92 | +<li><p>(5.3) — […]</p></li> |
| 93 | +</ol> |
| 94 | +</blockquote> |
| 95 | +</blockquote> |
| 96 | + |
| 97 | +</li> |
| 98 | + |
| 99 | +</ol> |
| 100 | + |
| 101 | +</resolution> |
| 102 | + |
| 103 | +</issue> |
0 commit comments