|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4183" status="New"> |
| 5 | +<title>`subrange` should provide `data()`</title> |
| 6 | +<section><sref ref="[range.subrange.general]"/><sref ref="[range.subrange.general]"/></section> |
| 7 | +<submitter>Hewill Kang</submitter> |
| 8 | +<date>16 Dec 2024</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +Currently, only four view classes in <code><ranges></code> explicitly provide `data()` members. |
| 14 | +</p> |
| 15 | +<p> |
| 16 | +Two of them are `empty_view` and `single_view`, because their `data()` is always valid |
| 17 | +and can be marked `noexcept`. |
| 18 | +</p> |
| 19 | +<p> |
| 20 | +The remaining two are `ref_view` and `owning_view` with constrained `data()`, |
| 21 | +which is redundant since `data()` can always obtained from `view_interface` |
| 22 | +when the underlying range is contiguous. I suspect this is because `ranges::data` |
| 23 | +is more efficient. |
| 24 | +</p> |
| 25 | +<p> |
| 26 | +However, `subrange` does not have a `data()` member, which seems worth considering |
| 27 | +because this function can always be `noexcept` given that `to_address` is always `noexcept`. |
| 28 | +</p> |
| 29 | +</discussion> |
| 30 | + |
| 31 | +<resolution> |
| 32 | +<p> |
| 33 | +This wording is relative to <paper num="N5001"/>. |
| 34 | +</p> |
| 35 | + |
| 36 | +<ol> |
| 37 | +<li><p>Modify <sref ref="[range.subrange.general]"/> as indicated:</p> |
| 38 | + |
| 39 | +<blockquote> |
| 40 | +<pre> |
| 41 | +namespace std::ranges { |
| 42 | + […] |
| 43 | + template<input_or_output_iterator I, sentinel_for<I> S = I, subrange_kind K = |
| 44 | + sized_sentinel_for<S, I> ? subrange_kind::sized : subrange_kind::unsized> |
| 45 | + requires (K == subrange_kind::sized || !sized_sentinel_for<S, I>) |
| 46 | + class subrange : public view_interface<subrange<I, S, K>> { |
| 47 | + […] |
| 48 | + constexpr bool empty() const; |
| 49 | + constexpr <i>make-unsigned-like-t</i><iter_difference_t<I>> size() const |
| 50 | + requires (K == subrange_kind::sized); |
| 51 | + <ins>constexpr auto data() const noexcept requires contiguous_iterator<I>;</ins> |
| 52 | + […] |
| 53 | + }; |
| 54 | + […] |
| 55 | +} |
| 56 | +</pre> |
| 57 | +</blockquote> |
| 58 | + |
| 59 | +</li> |
| 60 | + |
| 61 | +<li><p>Modify <sref ref="[range.subrange.access]"/> as indicated:</p> |
| 62 | + |
| 63 | +<blockquote> |
| 64 | +<pre> |
| 65 | +constexpr <i>make-unsigned-like-t</i><iter_difference_t<I>> size() const |
| 66 | + requires (K == subrange_kind::sized); |
| 67 | +</pre> |
| 68 | +<blockquote> |
| 69 | +<p> |
| 70 | +-5- <i>Effects</i>: |
| 71 | +<p/> |
| 72 | +[…] |
| 73 | +</p> |
| 74 | +</blockquote> |
| 75 | +<pre> |
| 76 | +<ins>constexpr auto data() const noexcept requires contiguous_iterator<I>;</ins> |
| 77 | +</pre> |
| 78 | +<blockquote> |
| 79 | +<p> |
| 80 | +<ins>-?- <i>Effects</i>: Equivalent to: <code>to_address(<i>begin_</i>);</code></ins> |
| 81 | +</p> |
| 82 | +</blockquote> |
| 83 | +</blockquote> |
| 84 | + |
| 85 | +</li> |
| 86 | + |
| 87 | +</ol> |
| 88 | +</resolution> |
| 89 | + |
| 90 | +</issue> |
0 commit comments