Skip to content

Commit 8b67487

Browse files
committed
New issue from Jiang An: "P1148R0 changed the return values of searching functions of std::basic_string on some platforms"
1 parent 6ca5c54 commit 8b67487

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

xml/issue4259.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4259" status="New">
5+
<title>P1148R0 changed the return values of searching functions of `std::basic_string` on some platforms</title>
6+
<section><sref ref="[string.find]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>5 May 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
<paper num="P1148R0"/> respecified the searching functions of `std::basic_string` to return
14+
corresponding string view type's `npos` member constant (equal to `std::size_t(-1)`), converted
15+
to the string type `S`'s member `S::size_type`, when the search fails. Before the change,
16+
`S::npos` (equal to `S::size_type(-1)`) was returned on failure.
17+
<p/>
18+
On platforms where `std::size_t` isn't the widest unsigned integer type (e.g. on usual 32-bit
19+
platforms), the return value can change. Because there can be an allocator with a wider size_type,
20+
and when the basic_string type `S` uses such an allocator, `S::size_type` is specified to be that
21+
type, which in turn makes `S::size_type(std::size_t(-1))` not equal to `S::size_type(-1)`.
22+
<p/>
23+
Do we want to restore the old return values?
24+
</p>
25+
</discussion>
26+
27+
<resolution>
28+
<p>
29+
This wording is relative to <paper num="N5008"/>.
30+
</p>
31+
<ol>
32+
33+
<li><p>Modify <sref ref="[string.find]"/> as indicated:</p>
34+
35+
<blockquote>
36+
<pre>
37+
template&lt;class T&gt;
38+
constexpr size_type find(const T&amp; t, size_type pos = 0) const noexcept(<i>see below</i>);
39+
[&hellip;]
40+
template&lt;class T&gt;
41+
constexpr size_type find_last_not_of(const T&amp; t, size_type pos = npos) const noexcept(<i>see below</i>);
42+
</pre>
43+
<blockquote>
44+
<p>
45+
-2- <i>Constraints</i>: [&hellip;]
46+
<p/>
47+
-3- <i>Effects</i>: Let <tt><i>G</i></tt> be the name of the function. Equivalent to:
48+
</p>
49+
<blockquote><pre>
50+
basic_string_view&lt;charT, traits&gt; s = *this, sv = t;
51+
<del>return s.<i>G</i>(sv, pos);</del>
52+
<ins>if (auto result = s.<i>G</i>(sv, pos); result == size_t(-1))
53+
return npos;
54+
else
55+
return result;</ins>
56+
</pre></blockquote>
57+
</blockquote>
58+
</blockquote>
59+
</li>
60+
</ol>
61+
</resolution>
62+
63+
</issue>

0 commit comments

Comments
 (0)