Skip to content

Commit cfce831

Browse files
committed
New issue from Jan Schultke: "basic_string accidentally fails to meet the reversible container requirements"
1 parent 9deea42 commit cfce831

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

xml/issue4029.xml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4029" status="New">
5+
<title><tt>basic_string</tt> accidentally fails to meet the reversible container requirements</title>
6+
<section><sref ref="[basic.string.general]"/></section>
7+
<submitter>Jan Schultke</submitter>
8+
<date>18 Dec 2023</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
The complexity requirements for a reversible container (<sref ref="[container.rev.reqmts]"/>) are that each
14+
function must have constant complexity. The corresponding member functions in <sref ref="[string.iterators]"/>
15+
have no complexity requirements, and <tt>basic_string</tt> unintentionally is not a reversible container
16+
(unless the implementation coincidentally provides constant complexity member functions).
17+
</p>
18+
</discussion>
19+
20+
<resolution>
21+
<p>
22+
This wording is relative to <paper num="N4971"/>.
23+
</p>
24+
25+
<blockquote class="note">
26+
<p>
27+
[<i>Drafting Note:</i> The proposed wording is similar to the specification in <sref ref="[vector.overview]"/> p2
28+
and suggests to simply strike <sref ref="[string.iterators]"/>, because it doesn't say anything new compared to
29+
<sref ref="[container.reqmts]"/> and <sref ref="[container.rev.reqmts]"/>.
30+
<p/>
31+
Alternatively, one could add a
32+
<p/>
33+
<ins><i>Complexity</i>: Constant.</ins>
34+
<p/>
35+
paragraph to each function in <sref ref="[string.iterators]"/>, but that would be less clearer and would not
36+
explicitly say <tt>basic_string</tt> meets the reversible container requirements.
37+
]
38+
</p>
39+
</blockquote>
40+
41+
<ol>
42+
43+
<li><p>Modify <sref ref="[basic.string.general]"/> as indicated:</p>
44+
45+
<blockquote>
46+
<p>
47+
-2- A specialization of <tt>basic_string</tt> is a contiguous container <ins>and reversible container</ins>
48+
(<sref ref="[container.reqmts]"/>).
49+
<p/>
50+
-3- In all cases, <tt>[data(), data() + size()]</tt> is a valid range, <tt>data() + size()</tt> points at
51+
an object with value <tt>charT()</tt> (a "null terminator"), and <tt>size() &lt;= capacity()</tt> is <tt>true</tt>.
52+
</p>
53+
<blockquote><pre>
54+
namespace std {
55+
template&lt;class charT, class traits = char_traits&lt;charT&gt;,
56+
class Allocator = allocator&lt;charT&gt;&gt;
57+
class basic_string {
58+
[&hellip;]
59+
// <i><del><sref ref="[string.iterators]"/>,</del> iterators</i>
60+
constexpr iterator begin() noexcept;
61+
constexpr const_iterator begin() const noexcept;
62+
constexpr iterator end() noexcept;
63+
constexpr const_iterator end() const noexcept;
64+
65+
constexpr reverse_iterator rbegin() noexcept;
66+
constexpr const_reverse_iterator rbegin() const noexcept;
67+
constexpr reverse_iterator rend() noexcept;
68+
constexpr const_reverse_iterator rend() const noexcept;
69+
70+
constexpr const_iterator cbegin() const noexcept;
71+
constexpr const_iterator cend() const noexcept;
72+
constexpr const_reverse_iterator crbegin() const noexcept;
73+
constexpr const_reverse_iterator crend() const noexcept;
74+
75+
// <i><sref ref="[string.capacity]"/>, capacity</i>
76+
[&hellip;]
77+
};
78+
[&hellip;]
79+
}
80+
</pre></blockquote>
81+
[&hellip;]
82+
</blockquote>
83+
</li>
84+
85+
<li><p>Remove subclause <sref ref="[string.iterators]"/> in its entirety:</p>
86+
87+
<blockquote>
88+
<p>
89+
<del><b>23.4.3.4 Iterator support [string.iterators]</b></del>
90+
</p>
91+
<pre>
92+
<del>constexpr iterator begin() noexcept;
93+
constexpr const_iterator begin() const noexcept;
94+
constexpr const_iterator cbegin() const noexcept;</del>
95+
</pre>
96+
<blockquote>
97+
<p>
98+
<del>-1- <i>Returns</i>: An iterator referring to the first character in the string.</del>
99+
</p>
100+
</blockquote>
101+
[&hellip;]
102+
<pre>
103+
<del>constexpr reverse_iterator rend() noexcept;
104+
constexpr const_reverse_iterator rend() const noexcept;
105+
constexpr const_reverse_iterator crend() const noexcept;</del>
106+
</pre>
107+
<blockquote>
108+
<p>
109+
<del>-4- <i>Returns</i>: An iterator which is semantically equivalent to <tt>reverse_iterator(begin())</tt>.</del>
110+
</p>
111+
</blockquote>
112+
</blockquote>
113+
114+
</li>
115+
116+
</ol>
117+
118+
119+
</resolution>
120+
121+
</issue>

0 commit comments

Comments
 (0)