<div dir="ltr">Your four Examples are excellent. I do wish you&#39;d present them in Tony-table form, though: IIUC today each of the four examples is ill-formed (rejected at compile-time), and after P4173 they&#39;d all be well-formed and Do The Right Thing, is that correct?<div><br></div><div>The main thing I worry about is that your proposal essentially nerfs any optimization potential inside the implementation. You write:</div><div>&gt; mdspan essentially treats multi-dimensional access as a layer on top of contiguous memory, rather than a generalized abstraction for any indexed data source.</div><div>But is it just &quot;<i>treating</i>&quot; multi-dimensional access as a layer on top of contiguous memory, interface-wise; or does mdspan internally <i><b>implement</b></i> multi-dimensional access as raw-pointer operations, in order to reduce code bloat and to reduce pressure on the compiler&#39;s optimizer?  I fear mdspan does the latter.</div><div>So I fear that your proposal is basically asking implementors to implement (certain parts of) mdspan twice: one time for contiguous iterators, which can be lowered to raw pointers; and a second time (non-existent today, but forced by your proposal) for random-access-but-non-contiguous iterators, which will be forbidden to use any clever optimizations.<br><div>I&#39;m not necessarily right about that fear; and even if implementors <i>are</i> forced to implement two codepaths, there&#39;s certainly precedent in the STL for that.</div><div><br></div></div><div>But basically this indicates that your D4173R0 is conspicuously missing an &quot;Implementation experience&quot; section.</div><div><br></div><div>Nit: &quot;Lastest&quot; should be &quot;Latest.&quot;</div><div>Bikeshed: &quot;__cpp_lib_iterator_accessor&quot; should perhaps be &quot;__cpp_lib_mdspan_iterator_accessor&quot; for clarity.</div><div>Pre-existing nit: Your <i>Mandates</i> element has the words &quot;is required to be&quot;; that should be just &quot;is&quot;. Do you feel like submitting an editorial PR for the pre-existing misuses of &quot;is required to be&quot; in [mdspan.accessor]?</div><div><br></div><div>You write:</div><div>&gt; -3- Each specialization of iterator_accessor is a trivially copyable type that models semiregular.</div><div>Is this &quot;trivially copyable&quot; implementable? <i>If iterator_accessor&lt;I&gt; contains an I data member</i>, it&#39;s not. At least this should say &quot;iterator_accessor&lt;I&gt; is trivially copyable if I is trivially copyable.&quot; Or, alternatively, add &quot;<i>Mandates:</i> I is trivially copyable.&quot;</div><div>The latter would be really annoying IMHO. However, it brings me back to my first fear: Is there a <i><b>reason</b></i> that all accessors are currently specified to be trivially copyable? Does that help the implementor somewhere later on, that we can copy (a contiguous array of) accessors with memcpy without knowing their exact type? If so, then permitting `iterator_accessor&lt;I&gt;` to be non-trivially copyable is going to be an implementation burden. So again, I want to see an &quot;Implementation Experience&quot; section and I want to see it deal with these (imagined/feared) optimization issues head-on.</div><div>Alternatively, <i>if iterator_accessor&lt;I&gt; does not contain an I data member,</i> then why stop at &quot;trivially copyable&quot;? Why not specify that iterator_accessor&lt;I&gt; is always an <i><b>empty</b></i> type? (And then, pre-existing, why do none of the other accessors bother to specify that? What data members are they imagined to have, then?)</div><div><br></div><div>Other than the big fear that this will turn out to be unimplementable for some technical reason, IMHO this sounds great. Again, those four Examples are very motivating.</div><div><br></div><div>HTH,</div><div>Arthur</div><div><br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Apr 1, 2026 at 10:01 AM Hewill Kang via Std-Proposals &lt;<a href="mailto:std-proposals@lists.isocpp.org">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi, I wrote a paper on this: <a href="https://isocpp.org/files/papers/P4173R0.html" target="_blank">https://isocpp.org/files/papers/P4173R0.html</a><br>Thanks.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hewill Kang &lt;<a href="mailto:hewillk@gmail.com" target="_blank">hewillk@gmail.com</a>&gt; 於 2026年3月30日週一 下午8:33寫道：<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<br><br>Currently, although `mdspan` is designed as a general-purpose multiview, it mostly accepts a pointer and accesses different elements through a pointer algorithm.<br>However, I am not satisfied with these <i>pointer</i>-based mandates because I do not think they are much different from a general `contiguous_iterator`, which can be a common iterator such as `vector::iterator`.<br>If we look at the `default_accessor`, we can see the clue:<br><br>```cpp<br>template&lt;class ElementType&gt;<br>  struct default_accessor {<br>    using offset_policy = default_accessor;<br>    using element_type = ElementType;<br>    using reference = ElementType&amp;;<br>    using data_handle_type = <font color="#ff0000">ElementType*</font>;<br><br>    constexpr default_accessor() noexcept = default;<br>    constexpr reference access(data_handle_type p, size_t i) const noexcept<div>      { return <font color="#ff0000">p[i]</font>; }<br>    constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept</div><div>      { return <font color="#ff0000">p + i</font>; }<br>  };<br>```<br>Then, upon closer inspection, we discovered that this is <i>exactly</i> the operation supported by C++20 `random_access_iterator`, i.e., `operator[]` and `operator+`.<br>Given this, I think we can introduce a new accessor class that wraps the `random_access_iterator`, for example:<br><br>```cpp<br>template&lt;<font color="#ff0000">random_access_iterator</font> I&gt;<br>  struct <b>iter_accessor</b> {<br>    using offset_policy = iter_accessor;<br>    using reference = iter_reference_t&lt;I&gt;;<br>    using element_type = remove_reference_t&lt;reference&gt;;<br>    using data_handle_type = I;<br><br>    iter_accessor() noexcept = default;<br>    constexpr reference <br>      access(data_handle_type p, std::iter_difference_t&lt;I&gt; i) const <br>        { return <font color="#ff0000">p[i]</font>; }<br>    constexpr data_handle_type <br>      offset(data_handle_type p, std::iter_difference_t&lt;I&gt; i) const<br>        { return <font color="#ff0000">p + i</font>; }<br>  };<br>```<br><br>This fully inherits the natural characteristics of a `random_access_iterator`, which allows us to very easily make `mdspan`s with a wide variety of different `random_access_range`s, such as:<br><br>```<br>  using Layout = std::layout_right::mapping&lt;std::extents&lt;int, 3, 3&gt;&gt;;<div><br>  auto r = std::views::<font color="#ff0000">iota</font>(0, 9);<br>  auto ms1 = std::mdspan(r.begin(), Layout{}, <b>iter_accessor</b>&lt;decltype(r.begin())&gt;{});<br>  /* 0 1 2 <br>     3 4 5 <br>     6 7 8 */<br><br>  auto v = std::<font color="#ff0000">vector&lt;bool&gt;</font>{true, false, true, false, true, false, true, false, true};<br>  auto ms2 = std::mdspan(v.begin(), Layout{}, <b>iter_accessor</b>&lt;decltype(v.begin())&gt;{});<br>  /* true false true <br>     false true false <br>     true false true */<br><br>  std::vector&lt;int&gt; v1{1, 2, 3}, v2{4, 5}, v3{};<br>  std::array a{6, 7, 8};<br>  auto s = std::views::single(9);<br>  auto r3 = std::views::<font color="#ff0000">concat</font>(v1, v2, v3, a, s);<br>  auto ms3 = std::mdspan(r3.begin(), Layout{}, <b>iter_accessor</b>&lt;decltype(r3.begin())&gt;{});<br>  /* 1 2 3 <br>      4 5 6 <br>      7 8 9 */<br>```<br>Demo: <a href="https://godbolt.org/z/xb5vrejba" target="_blank">https://godbolt.org/z/xb5vrejba</a><br><br>I think this is a very useful utility. <br>Based on C++26, we have a large majority of range adaptors in `&lt;ranges&gt;` that can support `random_access_range`.</div><div>Introducing this `accessor` makes them better integrated with `mdspan`, which also opens the door for third-party custom range types.<br><br>What do you think? Appreciate any feedback.<br><br>Hewill</div><div><br><br><br><br><div><div><span><span><div><div></div></div></span></span></div></div></div></div></div>
</blockquote></div>
</div>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>

