Skip to content

Commit e66529d

Browse files
committed
New issue from Jiang An: "Specification for some functions of bit reference types seems missing"
1 parent 5565152 commit e66529d

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

xml/issue4493.xml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4493" status="New">
5+
<title>Specification for some functions of bit reference types seems missing</title>
6+
<section><sref ref="[template.bitset.general]"/><sref ref="[vector.bool.pspc]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>16 Dec 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
We haven't explicitly specified the return values of <tt>bitset&lt;N&gt;::reference::operator bool()</tt> and
14+
<tt>vector&lt;bool, A&gt;::reference::operator bool()</tt>, although the intended return values can be inferred
15+
from "a class that simulates a reference to a single bit in the sequence". Moreover, specification for
16+
<tt>bitset&lt;N&gt;::reference::operator~</tt> seems completely missing, and the comment "flip the bit" seems
17+
misleading. Implementations consistently make the `operator~` return `!operator bool()`.
18+
</p>
19+
</discussion>
20+
21+
<resolution>
22+
<p>
23+
This wording is relative to <paper num="N5032"/>.
24+
</p>
25+
26+
<ol>
27+
<li><p>Modify <sref ref="[template.bitset.general]"/> as indicated:</p>
28+
29+
<blockquote>
30+
<blockquote>
31+
<pre>
32+
[&hellip;]
33+
<i>// bit reference</i>
34+
class reference {
35+
public:
36+
constexpr reference(const reference&amp; x) noexcept;
37+
constexpr ~reference();
38+
constexpr reference&amp; operator=(bool x) noexcept; // for b[i] = x;
39+
constexpr reference&amp; operator=(const reference&amp; x) noexcept; // for b[i] = b[j];
40+
constexpr const reference&amp; operator=(bool x) const noexcept;
41+
constexpr operator bool() const noexcept; // for x = b[i];
42+
constexpr bool operator~() const noexcept; <del>// flips the bit</del>
43+
constexpr reference&amp; flip() noexcept; // for b[i].flip();
44+
45+
friend constexpr void swap(reference x, reference y) noexcept;
46+
friend constexpr void swap(reference x, bool&amp; y) noexcept;
47+
friend constexpr void swap(bool&amp; x, reference y) noexcept;
48+
};
49+
[&hellip;]
50+
</pre>
51+
</blockquote>
52+
[&hellip;]
53+
<pre>
54+
constexpr reference&amp; reference::operator=(bool x) noexcept;
55+
constexpr reference&amp; reference::operator=(const reference&amp; x) noexcept;
56+
constexpr const reference&amp; reference::operator=(bool x) const noexcept;
57+
</pre>
58+
<blockquote>
59+
<p>
60+
-6- <i>Effects</i>: Sets the bit referred to by `*this` if `bool(x)` is `true`, and clears it otherwise.
61+
<p/>
62+
-7- <i>Returns</i>: `*this`.
63+
</p>
64+
</blockquote>
65+
<pre>
66+
<ins>constexpr reference::operator bool() const noexcept;</ins>
67+
</pre>
68+
<blockquote>
69+
<p>
70+
<ins>-?- <i>Returns</i>: `true` if the value of the referred to bit is one, `false` otherwise.</ins>
71+
</p>
72+
</blockquote>
73+
<pre>
74+
<ins>constexpr bool reference::operator~() const noexcept;</ins>
75+
</pre>
76+
<blockquote>
77+
<p>
78+
<ins>-?- <i>Returns</i>: `!bool(*this)`.</ins>
79+
</p>
80+
</blockquote>
81+
</blockquote>
82+
</li>
83+
84+
<li><p>Modify <sref ref="[vector.bool.pspc]"/> as indicated:</p>
85+
86+
<blockquote>
87+
[&hellip;]
88+
<pre>
89+
constexpr reference&amp; reference::operator=(bool x) noexcept;
90+
constexpr reference&amp; reference::operator=(const reference&amp; x) noexcept;
91+
constexpr const reference&amp; reference::operator=(bool x) const noexcept;
92+
</pre>
93+
<blockquote>
94+
<p>
95+
-7- <i>Effects</i>: Sets the bit referred to by `*this` when `bool(x)` is `true`, and clears it otherwise.
96+
<p/>
97+
-8- <i>Returns</i>: `*this`.
98+
</p>
99+
</blockquote>
100+
<pre>
101+
<ins>constexpr reference::operator bool() const noexcept;</ins>
102+
</pre>
103+
<blockquote>
104+
<p>
105+
<ins>-?- <i>Returns</i>: `true` if the value of the referred to bit is one, `false` otherwise.</ins>
106+
</p>
107+
</blockquote>
108+
</blockquote>
109+
</li>
110+
111+
</ol>
112+
113+
</resolution>
114+
115+
</issue>

0 commit comments

Comments
 (0)