Skip to content

Commit af003f3

Browse files
committed
P3612R1 Harmonize proxy-reference operations
1 parent b1ff1df commit af003f3

File tree

3 files changed

+183
-16
lines changed

3 files changed

+183
-16
lines changed

source/containers.tex

Lines changed: 66 additions & 13 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&) noexcept;
1048410484
constexpr ~reference();
1048510485
constexpr operator bool() const noexcept;
1048610486
constexpr reference& operator=(bool x) noexcept;
1048710487
constexpr reference& operator=(const reference& x) noexcept;
1048810488
constexpr const reference& operator=(bool x) 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}.
1061210611
\end{itemdescr}
1061310612

10614-
\indexlibrarymember{swap}{vector<bool>}%
10613+
\indexlibrarydtor{vector<bool>::reference}%
1061510614
\begin{itemdecl}
10616-
static constexpr void swap(reference x, reference y) noexcept;
10615+
constexpr reference::~reference();
1061710616
\end{itemdecl}
1061810617

1061910618
\begin{itemdescr}
1062010619
\pnum
1062110620
\effects
10622-
Exchanges the contents of \tcode{x} and \tcode{y} as if by:
10621+
None.
10622+
\end{itemdescr}
10623+
10624+
\indexlibrarymember{operator=}{vector<bool>::reference}%
10625+
\begin{itemdecl}
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;
10629+
\end{itemdecl}
10630+
10631+
\begin{itemdescr}
10632+
\pnum
10633+
\effects
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 \tode{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: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10409,13 +10409,18 @@
1040910409
// bit reference
1041010410
class reference {
1041110411
public:
10412-
constexpr reference(const reference&) = default;
10412+
constexpr reference(const reference&) noexcept;
1041310413
constexpr ~reference();
1041410414
constexpr reference& operator=(bool x) noexcept; // for \tcode{b[i] = x;}
10415-
constexpr reference& operator=(const reference&) noexcept; // for \tcode{b[i] = b[j];}
10415+
constexpr reference& operator=(const reference& x) noexcept; // for \tcode{b[i] = b[j];}
10416+
constexpr const reference& operator=(bool x) const noexcept;
1041610417
constexpr bool operator~() const noexcept; // flips the bit
1041710418
constexpr operator bool() const noexcept; // for \tcode{x = b[i];}
1041810419
constexpr reference& flip() noexcept; // for \tcode{b[i].flip();}
10420+
10421+
friend constexpr void swap(reference x, reference y) noexcept;
10422+
friend constexpr void swap(reference x, bool& y) noexcept;
10423+
friend constexpr void swap(bool& x, reference y) noexcept;
1041910424
};
1042010425

1042110426
// \ref{bitset.cons}, constructors
@@ -10502,7 +10507,7 @@
1050210507
zero.
1050310508
Each bit has a non-negative position \tcode{pos}.
1050410509
When converting
10505-
between an object of class
10510+
between an object of type
1050610511
\tcode{bitset<N>}
1050710512
and a value of some
1050810513
integral type, bit position \tcode{pos} corresponds to the
@@ -10511,6 +10516,84 @@
1051110516
The integral value corresponding to two
1051210517
or more bits is the sum of their bit values.
1051310518

10519+
\pnum
10520+
\tcode{reference}
10521+
is a class that simulates a reference to a single bit in the sequence.
10522+
10523+
\indexlibraryctor{bitset::reference}%
10524+
\begin{itemdecl}
10525+
constexpr reference::reference(const reference& x) noexcept;
10526+
\end{itemdecl}
10527+
10528+
\begin{itemdescr}
10529+
\pnum
10530+
\effects
10531+
Initializes \tcode{*this} to refer to the same bit as \tcode{x}.
10532+
\end{itemdescr}
10533+
10534+
\indexlibrarydtor{bitset::reference}%
10535+
\begin{itemdecl}
10536+
constexpr reference::~reference();
10537+
\end{itemdecl}
10538+
10539+
\begin{itemdescr}
10540+
\pnum
10541+
\effects
10542+
None.
10543+
\end{itemdescr}
10544+
10545+
\indexlibrarymember{operator=}{bitset::reference}%
10546+
\begin{itemdecl}
10547+
constexpr reference& reference::operator=(bool x) noexcept;
10548+
constexpr reference& reference::operator=(const reference& x) noexcept;
10549+
constexpr const reference& reference::operator=(bool x) const noexcept;
10550+
\end{itemdecl}
10551+
10552+
\begin{itemdescr}
10553+
\pnum
10554+
\effects
10555+
Sets the bit referred to by \tcode{*this} if \tcode{bool(x)} is \tcode{true},
10556+
and clears it otherwise.
10557+
10558+
\pnum
10559+
\returns
10560+
\tcode{*this}.
10561+
\end{itemdescr}
10562+
10563+
\indexlibrarymember{swap}{bitset::reference}%
10564+
\begin{itemdecl}
10565+
constexpr void swap(reference x, reference y) noexcept;
10566+
constexpr void swap(reference x, bool& y) noexcept;
10567+
constexpr void swap(bool& x, reference y) noexcept;
10568+
\end{itemdecl}
10569+
10570+
\begin{itemdescr}
10571+
\pnum
10572+
\effects
10573+
Exchanges the values denoted by \tcode{x} and \tcode{y} as if by:
10574+
10575+
\begin{codeblock}
10576+
bool b = x;
10577+
x = y;
10578+
y = b;
10579+
\end{codeblock}
10580+
\end{itemdescr}
10581+
10582+
\indexlibrarymember{flip}{bitset::reference}%
10583+
\begin{itemdecl}
10584+
constexpr reference& reference::flip() noexcept;
10585+
\end{itemdecl}
10586+
10587+
\begin{itemdescr}
10588+
\pnum
10589+
\effects
10590+
Equivalent to \tcode{*this = !*this}.
10591+
10592+
\pnum
10593+
\returns
10594+
\tocode{*this}.
10595+
\end{itemdescr}
10596+
1051410597
\pnum
1051510598
The functions described in \ref{template.bitset} can report three kinds of
1051610599
errors, each associated with a distinct exception:

0 commit comments

Comments
 (0)