Skip to content

Commit 7942b6a

Browse files
committed
New issue from Hewill: "subrange should provide data()"
1 parent 18ea97d commit 7942b6a

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

xml/issue4183.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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>&lt;ranges&gt;</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+
[&hellip;]
43+
template&lt;input_or_output_iterator I, sentinel_for&lt;I&gt; S = I, subrange_kind K =
44+
sized_sentinel_for&lt;S, I&gt; ? subrange_kind::sized : subrange_kind::unsized&gt;
45+
requires (K == subrange_kind::sized || !sized_sentinel_for&lt;S, I&gt;)
46+
class subrange : public view_interface&lt;subrange&lt;I, S, K&gt;&gt; {
47+
[&hellip;]
48+
constexpr bool empty() const;
49+
constexpr <i>make-unsigned-like-t</i>&lt;iter_difference_t&lt;I&gt;&gt; size() const
50+
requires (K == subrange_kind::sized);
51+
<ins>constexpr auto data() const noexcept requires contiguous_iterator&lt;I&gt;;</ins>
52+
[&hellip;]
53+
};
54+
[&hellip;]
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>&lt;iter_difference_t&lt;I&gt;&gt; size() const
66+
requires (K == subrange_kind::sized);
67+
</pre>
68+
<blockquote>
69+
<p>
70+
-5- <i>Effects</i>:
71+
<p/>
72+
[&hellip;]
73+
</p>
74+
</blockquote>
75+
<pre>
76+
<ins>constexpr auto data() const noexcept requires contiguous_iterator&lt;I&gt;;</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

Comments
 (0)