|
| 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<N>::reference::operator bool()</tt> and |
| 14 | +<tt>vector<bool, A>::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<N>::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 | +[…] |
| 33 | +<i>// bit reference</i> |
| 34 | +class reference { |
| 35 | +public: |
| 36 | + constexpr reference(const reference& x) noexcept; |
| 37 | + constexpr ~reference(); |
| 38 | + constexpr reference& operator=(bool x) noexcept; // for b[i] = x; |
| 39 | + constexpr reference& operator=(const reference& x) noexcept; // for b[i] = b[j]; |
| 40 | + constexpr const reference& 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& 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& y) noexcept; |
| 47 | + friend constexpr void swap(bool& x, reference y) noexcept; |
| 48 | +}; |
| 49 | +[…] |
| 50 | +</pre> |
| 51 | +</blockquote> |
| 52 | +[…] |
| 53 | +<pre> |
| 54 | +constexpr reference& reference::operator=(bool x) noexcept; |
| 55 | +constexpr reference& reference::operator=(const reference& x) noexcept; |
| 56 | +constexpr const reference& 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 | +[…] |
| 88 | +<pre> |
| 89 | +constexpr reference& reference::operator=(bool x) noexcept; |
| 90 | +constexpr reference& reference::operator=(const reference& x) noexcept; |
| 91 | +constexpr const reference& 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