|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4565" status="New"> |
| 5 | +<title><code>subrange</code> should prevent slicing for contiguous iterators</title> |
| 6 | +<section> |
| 7 | +<sref ref="[range.subrange.general]"/> |
| 8 | +</section> |
| 9 | +<submitter>Hewill Kang</submitter> |
| 10 | +<date>03 Apr 2026</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +Currently, the <code>subrange</code> uses the following exposition-only concept: |
| 16 | +</p> |
| 17 | +<blockquote><pre> |
| 18 | +template<class From, class To> |
| 19 | + concept <i>uses-nonqualification-pointer-conversion</i> = // <i>exposition only</i> |
| 20 | + is_pointer_v<From> && is_pointer_v<To> && |
| 21 | + !convertible_to<remove_pointer_t<From>(*)[], remove_pointer_t<To>(*)[]>; |
| 22 | +</pre></blockquote> |
| 23 | +<p> |
| 24 | +to disallow derived to base conversions. However, this only applies to pointers. |
| 25 | +</p> |
| 26 | +<p> |
| 27 | +Given that <code>subrange</code> is intended to universally take any iterator-pair to |
| 28 | +form a view, we may need to generally prevent this in the case of contiguous iterators |
| 29 | +(<a href="https://godbolt.org/z/oPvvExxaT">demo</a>): |
| 30 | +</p> |
| 31 | +<blockquote><pre> |
| 32 | +struct Base {}; |
| 33 | +struct Derived : Base {}; |
| 34 | +ranges::subrange<Derived*> sd; |
| 35 | +ranges::subrange<Base*> sb = sd; // error |
| 36 | +ranges::subrange<const Base*> sb = views::as_const(sd); // <span style="color:#C80000;font-weight:bold">ok</span> |
| 37 | +</pre></blockquote> |
| 38 | +</discussion> |
| 39 | + |
| 40 | +<resolution> |
| 41 | +<p> |
| 42 | +This wording is relative to <paper num="N5032"/>. |
| 43 | +</p> |
| 44 | + |
| 45 | +<ol> |
| 46 | +<li> |
| 47 | +<p>Modify <sref ref="[range.subrange.general]"/> as indicated:</p> |
| 48 | + |
| 49 | +<blockquote> |
| 50 | +<pre> |
| 51 | +namespace std::ranges { |
| 52 | + template<class From, class To> |
| 53 | + concept <i>uses-nonqualification-pointer-conversion</i> = // <i>exposition only</i> |
| 54 | + <del>is_pointer_v</del><ins>contiguous_iterator</ins><From> && <del>is_pointer_v</del><ins>contiguous_iterator</ins><To> && |
| 55 | + !convertible_to<<del>remove_pointer_t</del><ins>remove_reference_t<iter_reference_t</ins><From><ins>></ins>(*)[], |
| 56 | + <del>remove_pointer_t</del><ins>remove_reference_t<iter_reference_t</ins><To><ins>></ins>(*)[]>; |
| 57 | + […] |
| 58 | +} |
| 59 | +</pre> |
| 60 | +</blockquote> |
| 61 | +</li> |
| 62 | + |
| 63 | +</ol> |
| 64 | +</resolution> |
| 65 | + |
| 66 | +</issue> |
0 commit comments