Skip to content

Commit 5014a9c

Browse files
authored
Merge 2025-11 LWG Motion 12
P3612R1 Harmonize proxy-reference operations (LWG 3638 and 4187)
2 parents daa09e5 + 5702f5c commit 5014a9c

File tree

3 files changed

+185
-18
lines changed

3 files changed

+185
-18
lines changed

source/containers.tex

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10480,13 +10480,17 @@
1048010480
// bit reference
1048110481
class @\libmember{reference}{vector<bool>}@ {
1048210482
public:
10483-
constexpr reference(const reference&) = default;
10483+
constexpr reference(const reference& x) noexcept;
1048410484
constexpr ~reference();
10485-
constexpr operator bool() const noexcept;
1048610485
constexpr reference& operator=(bool x) noexcept;
1048710486
constexpr reference& operator=(const reference& x) noexcept;
1048810487
constexpr const reference& operator=(bool x) const noexcept;
10488+
constexpr operator bool() const noexcept;
1048910489
constexpr void flip() noexcept; // flips the bit
10490+
10491+
friend constexpr void swap(reference x, reference y) noexcept;
10492+
friend constexpr void swap(reference x, bool& y) noexcept;
10493+
friend constexpr void swap(bool& x, reference y) noexcept;
1049010494
};
1049110495

1049210496
// construct/copy/destroy
@@ -10572,7 +10576,6 @@
1057210576
constexpr void swap(vector&)
1057310577
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1057410578
allocator_traits<Allocator>::is_always_equal::value);
10575-
static constexpr void swap(reference x, reference y) noexcept;
1057610579
constexpr void flip() noexcept; // flips all bits
1057710580
constexpr void clear() noexcept;
1057810581
};
@@ -10594,39 +10597,89 @@
1059410597

1059510598
\pnum
1059610599
\tcode{reference}
10597-
is a class that simulates the behavior of references of a single bit in
10598-
\tcode{vector<bool>}. The conversion function returns \tcode{true}
10599-
when the bit is set, and \tcode{false} otherwise. The assignment operators
10600-
set the bit when the argument is (convertible to) \tcode{true} and
10601-
clear it otherwise. \tcode{flip} reverses the state of the bit.
10600+
is a class that simulates a reference to a single bit in the sequence.
1060210601

10603-
\indexlibrarymember{flip}{vector<bool>}%
10602+
\indexlibraryctor{vector<bool>::reference}%
1060410603
\begin{itemdecl}
10605-
constexpr void flip() noexcept;
10604+
constexpr reference::reference(const reference& x) noexcept;
1060610605
\end{itemdecl}
1060710606

1060810607
\begin{itemdescr}
1060910608
\pnum
1061010609
\effects
10611-
Replaces each element in the container with its complement.
10610+
Initializes \tcode{*this} to refer to the same bit as \tcode{x}.
10611+
\end{itemdescr}
10612+
10613+
\indexlibrarydtor{vector<bool>::reference}%
10614+
\begin{itemdecl}
10615+
constexpr reference::~reference();
10616+
\end{itemdecl}
10617+
10618+
\begin{itemdescr}
10619+
\pnum
10620+
\effects
10621+
None.
1061210622
\end{itemdescr}
1061310623

10614-
\indexlibrarymember{swap}{vector<bool>}%
10624+
\indexlibrarymember{operator=}{vector<bool>::reference}%
1061510625
\begin{itemdecl}
10616-
static constexpr void swap(reference x, reference y) noexcept;
10626+
constexpr reference& reference::operator=(bool x) noexcept;
10627+
constexpr reference& reference::operator=(const reference& x) noexcept;
10628+
constexpr const reference& reference::operator=(bool x) const noexcept;
1061710629
\end{itemdecl}
1061810630

1061910631
\begin{itemdescr}
1062010632
\pnum
1062110633
\effects
10622-
Exchanges the contents of \tcode{x} and \tcode{y} as if by:
10634+
Sets the bit referred to by \tcode{*this} when \tcode{bool(x)} is \tcode{true},
10635+
and clears it otherwise.
10636+
10637+
\pnum
10638+
\returns
10639+
\tcode{*this}.
10640+
\end{itemdescr}
10641+
10642+
\indexlibrarymember{flip}{vector<bool>::reference}%
10643+
\begin{itemdecl}
10644+
constexpr void reference::flip() noexcept;
10645+
\end{itemdecl}
10646+
10647+
\begin{itemdescr}
10648+
\pnum
10649+
\effects
10650+
Equivalent to \tcode{*this = !*this}.
10651+
\end{itemdescr}
10652+
10653+
\indexlibrarymember{swap}{vector<bool>::reference}%
10654+
\begin{itemdecl}
10655+
constexpr void swap(reference x, reference y) noexcept;
10656+
constexpr void swap(reference x, bool& y) noexcept;
10657+
constexpr void swap(bool& x, reference y) noexcept;
10658+
\end{itemdecl}
10659+
10660+
\begin{itemdescr}
10661+
\pnum
10662+
\effects
10663+
Exchanges the values denoted by \tcode{x} and \tcode{y} as if by:
1062310664

1062410665
\begin{codeblock}
1062510666
bool b = x;
1062610667
x = y;
1062710668
y = b;
1062810669
\end{codeblock}
10670+
\end{itemdescr}
1062910671

10672+
10673+
10674+
\indexlibrarymember{flip}{vector<bool>}%
10675+
\begin{itemdecl}
10676+
constexpr void flip() noexcept;
10677+
\end{itemdecl}
10678+
10679+
\begin{itemdescr}
10680+
\pnum
10681+
\effects
10682+
Replaces each element in the container with its complement.
1063010683
\end{itemdescr}
1063110684

1063210685
\begin{itemdecl}

source/future.tex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,37 @@
636636
\end{itemize}
637637
\end{itemdescr}
638638

639+
\rSec1[depr.vector.bool.swap]{Deprecated \tcode{vector<bool, Allocator>} swap}
640+
641+
\pnum
642+
The following member is declared in addition to those members specified in
643+
\ref{vector.bool}:
644+
645+
\begin{codeblock}
646+
namespace std {
647+
template<class Allocator> class vector<bool, Allocator> {
648+
public:
649+
static constexpr void swap(reference x, reference y) noexcept;
650+
};
651+
}
652+
\end{codeblock}
653+
654+
\indexlibrarymember{swap}{vector<bool>}%
655+
\begin{itemdecl}
656+
static constexpr void swap(reference x, reference y) noexcept;
657+
\end{itemdecl}
658+
659+
\begin{itemdescr}
660+
\pnum
661+
\effects
662+
Exchanges the values denoted by \tcode{x} and \tcode{y} as if by:
663+
\begin{codeblock}
664+
bool b = x;
665+
x = y;
666+
y = b;
667+
\end{codeblock}
668+
\end{itemdescr}
669+
639670
\rSec1[depr.iterator]{Deprecated \tcode{iterator} class template}
640671

641672
\pnum

source/utilities.tex

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10518,13 +10518,18 @@
1051810518
// bit reference
1051910519
class reference {
1052010520
public:
10521-
constexpr reference(const reference&) = default;
10521+
constexpr reference(const reference& x) noexcept;
1052210522
constexpr ~reference();
1052310523
constexpr reference& operator=(bool x) noexcept; // for \tcode{b[i] = x;}
10524-
constexpr reference& operator=(const reference&) noexcept; // for \tcode{b[i] = b[j];}
10525-
constexpr bool operator~() const noexcept; // flips the bit
10524+
constexpr reference& operator=(const reference& x) noexcept; // for \tcode{b[i] = b[j];}
10525+
constexpr const reference& operator=(bool x) const noexcept;
1052610526
constexpr operator bool() const noexcept; // for \tcode{x = b[i];}
10527+
constexpr bool operator~() const noexcept; // flips the bit
1052710528
constexpr reference& flip() noexcept; // for \tcode{b[i].flip();}
10529+
10530+
friend constexpr void swap(reference x, reference y) noexcept;
10531+
friend constexpr void swap(reference x, bool& y) noexcept;
10532+
friend constexpr void swap(bool& x, reference y) noexcept;
1052810533
};
1052910534

1053010535
// \ref{bitset.cons}, constructors
@@ -10611,7 +10616,7 @@
1061110616
zero.
1061210617
Each bit has a non-negative position \tcode{pos}.
1061310618
When converting
10614-
between an object of class
10619+
between an object of type
1061510620
\tcode{bitset<N>}
1061610621
and a value of some
1061710622
integral type, bit position \tcode{pos} corresponds to the
@@ -10620,6 +10625,84 @@
1062010625
The integral value corresponding to two
1062110626
or more bits is the sum of their bit values.
1062210627

10628+
\pnum
10629+
\tcode{reference}
10630+
is a class that simulates a reference to a single bit in the sequence.
10631+
10632+
\indexlibraryctor{bitset::reference}%
10633+
\begin{itemdecl}
10634+
constexpr reference::reference(const reference& x) noexcept;
10635+
\end{itemdecl}
10636+
10637+
\begin{itemdescr}
10638+
\pnum
10639+
\effects
10640+
Initializes \tcode{*this} to refer to the same bit as \tcode{x}.
10641+
\end{itemdescr}
10642+
10643+
\indexlibrarydtor{bitset::reference}%
10644+
\begin{itemdecl}
10645+
constexpr reference::~reference();
10646+
\end{itemdecl}
10647+
10648+
\begin{itemdescr}
10649+
\pnum
10650+
\effects
10651+
None.
10652+
\end{itemdescr}
10653+
10654+
\indexlibrarymember{operator=}{bitset::reference}%
10655+
\begin{itemdecl}
10656+
constexpr reference& reference::operator=(bool x) noexcept;
10657+
constexpr reference& reference::operator=(const reference& x) noexcept;
10658+
constexpr const reference& reference::operator=(bool x) const noexcept;
10659+
\end{itemdecl}
10660+
10661+
\begin{itemdescr}
10662+
\pnum
10663+
\effects
10664+
Sets the bit referred to by \tcode{*this} if \tcode{bool(x)} is \tcode{true},
10665+
and clears it otherwise.
10666+
10667+
\pnum
10668+
\returns
10669+
\tcode{*this}.
10670+
\end{itemdescr}
10671+
10672+
\indexlibrarymember{swap}{bitset::reference}%
10673+
\begin{itemdecl}
10674+
constexpr void swap(reference x, reference y) noexcept;
10675+
constexpr void swap(reference x, bool& y) noexcept;
10676+
constexpr void swap(bool& x, reference y) noexcept;
10677+
\end{itemdecl}
10678+
10679+
\begin{itemdescr}
10680+
\pnum
10681+
\effects
10682+
Exchanges the values denoted by \tcode{x} and \tcode{y} as if by:
10683+
10684+
\begin{codeblock}
10685+
bool b = x;
10686+
x = y;
10687+
y = b;
10688+
\end{codeblock}
10689+
\end{itemdescr}
10690+
10691+
\indexlibrarymember{flip}{bitset::reference}%
10692+
\begin{itemdecl}
10693+
constexpr reference& reference::flip() noexcept;
10694+
\end{itemdecl}
10695+
10696+
\begin{itemdescr}
10697+
\pnum
10698+
\effects
10699+
Equivalent to \tcode{*this = !*this}.
10700+
10701+
\pnum
10702+
\returns
10703+
\tcode{*this}.
10704+
\end{itemdescr}
10705+
1062310706
\pnum
1062410707
The functions described in \ref{template.bitset} can report three kinds of
1062510708
errors, each associated with a distinct exception:

0 commit comments

Comments
 (0)