From f9d877499dfa4cbd13c73046043bca87603d9360 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Tue, 25 Nov 2025 10:58:03 +0700 Subject: [PATCH 1/2] P3612R1 Harmonize proxy-reference operations --- source/containers.tex | 79 +++++++++++++++++++++++++++++++------- source/future.tex | 31 +++++++++++++++ source/utilities.tex | 89 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 183 insertions(+), 16 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index dc9719bf3b..8ebbd2116d 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10480,13 +10480,17 @@ // bit reference class @\libmember{reference}{vector}@ { public: - constexpr reference(const reference&) = default; + constexpr reference(const reference& x) noexcept; constexpr ~reference(); constexpr operator bool() const noexcept; constexpr reference& operator=(bool x) noexcept; constexpr reference& operator=(const reference& x) noexcept; constexpr const reference& operator=(bool x) const noexcept; constexpr void flip() noexcept; // flips the bit + + 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; }; // construct/copy/destroy @@ -10572,7 +10576,6 @@ constexpr void swap(vector&) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); - static constexpr void swap(reference x, reference y) noexcept; constexpr void flip() noexcept; // flips all bits constexpr void clear() noexcept; }; @@ -10594,39 +10597,89 @@ \pnum \tcode{reference} -is a class that simulates the behavior of references of a single bit in -\tcode{vector}. The conversion function returns \tcode{true} -when the bit is set, and \tcode{false} otherwise. The assignment operators -set the bit when the argument is (convertible to) \tcode{true} and -clear it otherwise. \tcode{flip} reverses the state of the bit. +is a class that simulates a reference to a single bit in the sequence. -\indexlibrarymember{flip}{vector}% +\indexlibraryctor{vector::reference}% \begin{itemdecl} -constexpr void flip() noexcept; +constexpr reference::reference(const reference& x) noexcept; \end{itemdecl} \begin{itemdescr} \pnum \effects -Replaces each element in the container with its complement. +Initializes \tcode{*this} to refer to the same bit as \tcode{x}. \end{itemdescr} -\indexlibrarymember{swap}{vector}% +\indexlibrarydtor{vector::reference}% \begin{itemdecl} -static constexpr void swap(reference x, reference y) noexcept; +constexpr reference::~reference(); \end{itemdecl} \begin{itemdescr} \pnum \effects -Exchanges the contents of \tcode{x} and \tcode{y} as if by: +None. +\end{itemdescr} + +\indexlibrarymember{operator=}{vector::reference}% +\begin{itemdecl} +constexpr reference& reference::operator=(bool x) noexcept; +constexpr reference& reference::operator=(const reference& x) noexcept; +constexpr const reference& reference::operator=(bool x) const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Sets the bit referred to by \tcode{*this} when \tcode{bool(x)} is \tcode{true}, +and clears it otherwise. + +\pnum +\returns +\tcode{*this}. +\end{itemdescr} + +\indexlibrarymember{flip}{vector::reference}% +\begin{itemdecl} +constexpr void reference::flip() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to \tcode{*this = !*this}. +\end{itemdescr} + +\indexlibrarymember{swap}{vector::reference}% +\begin{itemdecl} +constexpr void swap(reference x, reference y) noexcept; +constexpr void swap(reference x, bool& y) noexcept; +constexpr void swap(bool& x, reference y) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Exchanges the values denoted by \tcode{x} and \tcode{y} as if by: \begin{codeblock} bool b = x; x = y; y = b; \end{codeblock} +\end{itemdescr} + + +\indexlibrarymember{flip}{vector}% +\begin{itemdecl} +constexpr void flip() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Replaces each element in the container with its complement. \end{itemdescr} \begin{itemdecl} diff --git a/source/future.tex b/source/future.tex index 60ebd4d2e5..8c51c8522a 100644 --- a/source/future.tex +++ b/source/future.tex @@ -636,6 +636,37 @@ \end{itemize} \end{itemdescr} +\rSec1[depr.vector.bool.swap]{Deprecated \tode{vector} swap} + +\pnum +The following member is declared in addition to those members specified in +\ref{vector.bool}: + +\begin{codeblock} +namespace std { + template class vector { + public: + static constexpr void swap(reference x, reference y) noexcept; + }; +} +\end{codeblock} + +\indexlibrarymember{swap}{vector}% +\begin{itemdecl} +static constexpr void swap(reference x, reference y) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Exchanges the values denoted by \tcode{x} and \tcode{y} as if by: +\begin{codeblock} +bool b = x; +x = y; +y = b; +\end{codeblock} +\end{itemdescr} + \rSec1[depr.iterator]{Deprecated \tcode{iterator} class template} \pnum diff --git a/source/utilities.tex b/source/utilities.tex index a7975824a7..995989b645 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -10409,13 +10409,18 @@ // bit reference class reference { public: - constexpr reference(const reference&) = default; + constexpr reference(const reference& x) noexcept; constexpr ~reference(); constexpr reference& operator=(bool x) noexcept; // for \tcode{b[i] = x;} - constexpr reference& operator=(const reference&) noexcept; // for \tcode{b[i] = b[j];} + constexpr reference& operator=(const reference& x) noexcept; // for \tcode{b[i] = b[j];} + constexpr const reference& operator=(bool x) const noexcept; constexpr bool operator~() const noexcept; // flips the bit constexpr operator bool() const noexcept; // for \tcode{x = b[i];} constexpr reference& flip() noexcept; // for \tcode{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; }; // \ref{bitset.cons}, constructors @@ -10502,7 +10507,7 @@ zero. Each bit has a non-negative position \tcode{pos}. When converting -between an object of class +between an object of type \tcode{bitset} and a value of some integral type, bit position \tcode{pos} corresponds to the @@ -10511,6 +10516,84 @@ The integral value corresponding to two or more bits is the sum of their bit values. +\pnum +\tcode{reference} +is a class that simulates a reference to a single bit in the sequence. + +\indexlibraryctor{bitset::reference}% +\begin{itemdecl} +constexpr reference::reference(const reference& x) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Initializes \tcode{*this} to refer to the same bit as \tcode{x}. +\end{itemdescr} + +\indexlibrarydtor{bitset::reference}% +\begin{itemdecl} +constexpr reference::~reference(); +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +None. +\end{itemdescr} + +\indexlibrarymember{operator=}{bitset::reference}% +\begin{itemdecl} +constexpr reference& reference::operator=(bool x) noexcept; +constexpr reference& reference::operator=(const reference& x) noexcept; +constexpr const reference& reference::operator=(bool x) const noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Sets the bit referred to by \tcode{*this} if \tcode{bool(x)} is \tcode{true}, +and clears it otherwise. + +\pnum +\returns +\tcode{*this}. +\end{itemdescr} + +\indexlibrarymember{swap}{bitset::reference}% +\begin{itemdecl} +constexpr void swap(reference x, reference y) noexcept; +constexpr void swap(reference x, bool& y) noexcept; +constexpr void swap(bool& x, reference y) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Exchanges the values denoted by \tcode{x} and \tcode{y} as if by: + +\begin{codeblock} +bool b = x; +x = y; +y = b; +\end{codeblock} +\end{itemdescr} + +\indexlibrarymember{flip}{bitset::reference}% +\begin{itemdecl} +constexpr reference& reference::flip() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to \tcode{*this = !*this}. + +\pnum +\returns +\tocode{*this}. +\end{itemdescr} + \pnum The functions described in \ref{template.bitset} can report three kinds of errors, each associated with a distinct exception: From 54f76fcd9f6d9991419ee979951711c8afc76e94 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Fri, 28 Nov 2025 10:23:02 +0700 Subject: [PATCH 2/2] [template.bitset.general][vector.bool.pspc] Reorder reference members Reorder the members of `reference` classes to be consistent with each other and elsewhere. First list constructors, destructor, and assignment operator. Then list accessors, and finally modifiers. Keep unary `operator~` adjacent to `flip` where both are present. --- source/containers.tex | 2 +- source/utilities.tex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index 8ebbd2116d..2c6d4ccc69 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10482,10 +10482,10 @@ public: constexpr reference(const reference& x) noexcept; constexpr ~reference(); - constexpr operator bool() const noexcept; constexpr reference& operator=(bool x) noexcept; constexpr reference& operator=(const reference& x) noexcept; constexpr const reference& operator=(bool x) const noexcept; + constexpr operator bool() const noexcept; constexpr void flip() noexcept; // flips the bit friend constexpr void swap(reference x, reference y) noexcept; diff --git a/source/utilities.tex b/source/utilities.tex index 995989b645..e0b3f0317f 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -10414,8 +10414,8 @@ constexpr reference& operator=(bool x) noexcept; // for \tcode{b[i] = x;} constexpr reference& operator=(const reference& x) noexcept; // for \tcode{b[i] = b[j];} constexpr const reference& operator=(bool x) const noexcept; - constexpr bool operator~() const noexcept; // flips the bit constexpr operator bool() const noexcept; // for \tcode{x = b[i];} + constexpr bool operator~() const noexcept; // flips the bit constexpr reference& flip() noexcept; // for \tcode{b[i].flip();} friend constexpr void swap(reference x, reference y) noexcept; @@ -10591,7 +10591,7 @@ \pnum \returns -\tocode{*this}. +\tcode{*this}. \end{itemdescr} \pnum