This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
Section: 22.9.2.1 [template.bitset.general], 23.3.14.1 [vector.bool.pspc] Status: New Submitter: Jiang An Opened: 2025-12-16 Last modified: 2025-12-20
Priority: Not Prioritized
View all other issues in [template.bitset.general].
View all issues with New status.
Discussion:
We haven't explicitly specified the return values of bitset<N>::reference::operator bool() and
vector<bool, A>::reference::operator bool(), although the intended return values can be inferred
from "a class that simulates a reference to a single bit in the sequence". Moreover, specification for
bitset<N>::reference::operator~ seems completely missing, and the comment "flip the bit" seems
misleading. Implementations consistently make the operator~ return !operator bool().
Proposed resolution:
This wording is relative to N5032.
Modify 22.9.2.1 [template.bitset.general] as indicated:
[…][…] // bit reference class reference { public: constexpr reference(const reference& x) noexcept; constexpr ~reference(); constexpr reference& operator=(bool x) noexcept; // for b[i] = x; constexpr reference& operator=(const reference& x) noexcept; // for b[i] = b[j]; constexpr const reference& operator=(bool x) const noexcept; constexpr operator bool() const noexcept; // for x = b[i]; constexpr bool operator~() const noexcept;// flips the bitconstexpr reference& flip() noexcept; // for b[i].flip(); friend constexpr void swap(reference x, reference y) noexcept; friend constexpr void swap(reference x, bool& y) noexcept; friend constexpr void swap(bool& x, reference y) noexcept; }; […]constexpr reference& reference::operator=(bool x) noexcept; constexpr reference& reference::operator=(const reference& x) noexcept; constexpr const reference& reference::operator=(bool x) const noexcept;-6- Effects: Sets the bit referred to by
-7- Returns:*thisifbool(x)istrue, and clears it otherwise.*this.constexpr reference::operator bool() const noexcept;-?- Returns:
trueif the value of the referred to bit is one,falseotherwise.constexpr bool reference::operator~() const noexcept;-?- Returns:
!bool(*this).
Modify 23.3.14.1 [vector.bool.pspc] as indicated:
[…]constexpr reference& reference::operator=(bool x) noexcept; constexpr reference& reference::operator=(const reference& x) noexcept; constexpr const reference& reference::operator=(bool x) const noexcept;-7- Effects: Sets the bit referred to by
-8- Returns:*thiswhenbool(x)istrue, and clears it otherwise.*this.constexpr reference::operator bool() const noexcept;-?- Returns:
trueif the value of the referred to bit is one,falseotherwise.