4493. Specification for some functions of bit reference types seems missing

Section: 22.9.2.1 [template.bitset.general], 23.3.14.1 [vector.bool.pspc] Status: Tentatively Ready Submitter: Jiang An Opened: 2025-12-16 Last modified: 2026-02-18

Priority: Not Prioritized

View all other issues in [template.bitset.general].

View all issues with Tentatively Ready 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().

[2026-02-18; Reflector poll.]

Changed resolution to say "the bit referred to by *this" instead of "the referred to bit".

Set status to Tentatively Ready after six votes in favour during reflector poll.

Proposed resolution:

This wording is relative to N5032.

  1. 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 bit
      constexpr 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 *this if bool(x) is true, and clears it otherwise.

    -7- Returns: *this.

    constexpr reference::operator bool() const noexcept;
    

    -?- Returns: true if the value of bit referred to by *this is one, false otherwise.

    constexpr bool reference::operator~() const noexcept;
    

    -?- Returns: !bool(*this).

  2. 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 *this when bool(x) is true, and clears it otherwise.

    -8- Returns: *this.

    constexpr reference::operator bool() const noexcept;
    

    -?- Returns: true if the value of the bit referred to by *this is one, false otherwise.