From ae946dec00e9ee1f024630bbf6edfc6fbb5fc2e9 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Mon, 22 Dec 2025 11:52:35 -0500 Subject: [PATCH 1/2] [template.bitset.general] Break out 'bitset::reference' into its own subclause This change is consistent with specification of nested classes elsewhere in the standard, and allows better use of qualified names in the declaration of member functions in their own specification. --- source/utilities.tex | 131 +++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/source/utilities.tex b/source/utilities.tex index d714c1f2ef..c16b04be14 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -10533,22 +10533,8 @@ namespace std { template class bitset { public: - // bit reference - class reference { - public: - constexpr reference(const reference& x) noexcept; - constexpr ~reference(); - 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 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; - friend constexpr void swap(reference x, bool& y) noexcept; - friend constexpr void swap(bool& x, reference y) noexcept; - }; + // \ref{bitset.reference}, bit reference + class reference; // \ref{bitset.cons}, constructors constexpr bitset() noexcept; @@ -10625,6 +10611,8 @@ \tcode{bitset} describes an object that can store a sequence consisting of a fixed number of bits, \tcode{N}. +The class \tcode{bitset::reference} simulates a reference +to a single bit in the sequence. \pnum Each bit represents either the value zero (reset) or one (set). @@ -10644,12 +10632,55 @@ 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. +The functions described in \ref{template.bitset} can report three kinds of +errors, each associated with a distinct exception: +\begin{itemize} +\item +an +\term{invalid-argument} +error is associated with exceptions of type +\tcode{invalid_argument}\iref{invalid.argument}; +\indexlibraryglobal{invalid_argument}% +\item +an +\term{out-of-range} +error is associated with exceptions of type +\tcode{out_of_range}\iref{out.of.range}; +\indexlibraryglobal{out_of_range}% +\item +an +\term{overflow} +error is associated with exceptions of type +\tcode{overflow_error}\iref{overflow.error}. +\indexlibraryglobal{overflow_error}% +\end{itemize} + +\rSec3[bitset.reference]{Class \tcode{bitset::reference}}% +\indexlibrarymember{reference}{bitset}% +\begin{codeblock} +namespace std { + template + class bitset::reference { + public: + constexpr reference(const reference& x) noexcept; + constexpr ~reference(); + 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 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; + friend constexpr void swap(reference x, bool& y) noexcept; + friend constexpr void swap(bool& x, reference y) noexcept; + }; +} +\end{codeblock} \indexlibraryctor{bitset::reference}% \begin{itemdecl} -constexpr reference::reference(const reference& x) noexcept; +constexpr reference(const reference& x) noexcept; \end{itemdecl} \begin{itemdescr} @@ -10660,7 +10691,7 @@ \indexlibrarydtor{bitset::reference}% \begin{itemdecl} -constexpr reference::~reference(); +constexpr ~reference(); \end{itemdecl} \begin{itemdescr} @@ -10671,9 +10702,9 @@ \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; +constexpr reference& operator=(bool x) noexcept; +constexpr reference& operator=(const reference& x) noexcept; +constexpr const reference& operator=(bool x) const noexcept; \end{itemdecl} \begin{itemdescr} @@ -10687,6 +10718,21 @@ \tcode{*this}. \end{itemdescr} +\indexlibrarymember{flip}{bitset::reference}% +\begin{itemdecl} +constexpr reference& flip() noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\effects +Equivalent to \tcode{*this = !*this}. + +\pnum +\returns +\tcode{*this}. +\end{itemdescr} + \indexlibrarymember{swap}{bitset::reference}% \begin{itemdecl} constexpr void swap(reference x, reference y) noexcept; @@ -10706,45 +10752,6 @@ \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 -\tcode{*this}. -\end{itemdescr} - -\pnum -The functions described in \ref{template.bitset} can report three kinds of -errors, each associated with a distinct exception: -\begin{itemize} -\item -an -\term{invalid-argument} -error is associated with exceptions of type -\tcode{invalid_argument}\iref{invalid.argument}; -\indexlibraryglobal{invalid_argument}% -\item -an -\term{out-of-range} -error is associated with exceptions of type -\tcode{out_of_range}\iref{out.of.range}; -\indexlibraryglobal{out_of_range}% -\item -an -\term{overflow} -error is associated with exceptions of type -\tcode{overflow_error}\iref{overflow.error}. -\indexlibraryglobal{overflow_error}% -\end{itemize} - \rSec3[bitset.cons]{Constructors} \indexlibraryctor{bitset}% From c9a4561ee88022389809857683a8bb3b449ac654 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Mon, 22 Dec 2025 11:53:44 -0500 Subject: [PATCH 2/2] [vector.bool.pspc] Break out 'vector::reference' into its own subclause This change is consistent with specification of nested classes elsewhere in the standard, and allows better use of qualified names in the declaration of member functions in their own specification. --- source/containers.tex | 53 +++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/source/containers.tex b/source/containers.tex index 8e992682fd..303ebd124b 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -10489,21 +10489,8 @@ using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - // bit reference - class @\libmember{reference}{vector}@ { - public: - constexpr reference(const reference& x) noexcept; - constexpr ~reference(); - 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; - friend constexpr void swap(reference x, bool& y) noexcept; - friend constexpr void swap(bool& x, reference y) noexcept; - }; + // \ref{vector.bool.reference}, bit reference + class reference; // construct/copy/destroy constexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { } @@ -10607,13 +10594,35 @@ of \tcode{bool} values. A space-optimized representation of bits is recommended instead. +\rSec3[vector.bool.reference]{Class \tcode{vector::reference}}% \pnum \tcode{reference} is a class that simulates a reference to a single bit in the sequence. +\indexlibrarymember{reference}{vector}% +\begin{codeblock} +namespace std { + template + class vector::reference { + public: + constexpr reference(const reference& x) noexcept; + constexpr ~reference(); + 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; + friend constexpr void swap(reference x, bool& y) noexcept; + friend constexpr void swap(bool& x, reference y) noexcept; + }; +} +\end{codeblock} + \indexlibraryctor{vector::reference}% \begin{itemdecl} -constexpr reference::reference(const reference& x) noexcept; +constexpr reference(const reference& x) noexcept; \end{itemdecl} \begin{itemdescr} @@ -10624,7 +10633,7 @@ \indexlibrarydtor{vector::reference}% \begin{itemdecl} -constexpr reference::~reference(); +constexpr ~reference(); \end{itemdecl} \begin{itemdescr} @@ -10635,9 +10644,9 @@ \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; +constexpr reference& operator=(bool x) noexcept; +constexpr reference& operator=(const reference& x) noexcept; +constexpr const reference& operator=(bool x) const noexcept; \end{itemdecl} \begin{itemdescr} @@ -10653,7 +10662,7 @@ \indexlibrarymember{flip}{vector::reference}% \begin{itemdecl} -constexpr void reference::flip() noexcept; +constexpr void flip() noexcept; \end{itemdecl} \begin{itemdescr} @@ -10681,7 +10690,7 @@ \end{codeblock} \end{itemdescr} - +\rSec3[vector.bool.members]{\tcode{vector} members} \indexlibrarymember{flip}{vector}% \begin{itemdecl}