Skip to content

Commit 166762c

Browse files
authored
Merge 2021-10 LWG Motion 11
P1272R4 Byteswapping for fun&&nuf
2 parents 8f297c2 + 5e3760e commit 166762c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

source/numerics.tex

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@
12901290
template<class To, class From>
12911291
constexpr To bit_cast(const From& from) noexcept;
12921292

1293+
// \ref{bit.byteswap}, \tcode{byteswap}
1294+
template<class T>
1295+
constexpr T byteswap(T value) noexcept;
1296+
12931297
// \ref{bit.pow.two}, integral powers of 2
12941298
template<class T>
12951299
constexpr bool has_single_bit(T x) noexcept;
@@ -1355,6 +1359,15 @@
13551359
if there is no value of the object's type corresponding to the
13561360
value representation produced, the behavior is undefined.
13571361
If there are multiple such values, which value is produced is unspecified.
1362+
A bit in the value representation of the result is indeterminate if
1363+
it does not correspond to a bit in the value representation of \tcode{from} or
1364+
corresponds to a bit of an object that is not within its lifetime or
1365+
has an indeterminate value\iref{basic.indet}.
1366+
For each bit in the value representation of the result that is indeterminate,
1367+
the smallest object containing that bit has an indeterminate value;
1368+
the behavior is undefined unless that object is
1369+
of unsigned ordinary character type or \tcode{std::byte} type.
1370+
The result does not otherwise contain any indeterminate values.
13581371

13591372
\pnum
13601373
\remarks
@@ -1370,6 +1383,34 @@
13701383
\end{itemize}
13711384
\end{itemdescr}
13721385

1386+
\rSec2[bit.byteswap]{\tcode{byteswap}}
1387+
1388+
\indexlibraryglobal{byteswap}%
1389+
\begin{itemdecl}
1390+
template<class T>
1391+
constexpr T byteswap(T value) noexcept;
1392+
\end{itemdecl}
1393+
1394+
\begin{itemdescr}
1395+
\pnum
1396+
\constraints
1397+
\tcode{T} models \libconcept{integral}.
1398+
1399+
\pnum
1400+
\mandates
1401+
\tcode{T} does not have padding bits\iref{basic.types.general}.
1402+
1403+
\pnum
1404+
Let the sequence $R$ comprise
1405+
the bytes of the object representation of \tcode{value} in reverse order.
1406+
1407+
\pnum
1408+
\returns
1409+
An object \tcode{v} of type \tcode{T}
1410+
such that each byte in the object representation of \tcode{v} is equal to
1411+
the byte in the corresponding position in $R$.
1412+
\end{itemdescr}
1413+
13731414
\rSec2[bit.pow.two]{Integral powers of 2}
13741415

13751416
\indexlibraryglobal{has_single_bit}%

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@
579579
#define @\defnlibxname{cpp_lib_bounded_array_traits}@ 201902L // also in \libheader{type_traits}
580580
#define @\defnlibxname{cpp_lib_boyer_moore_searcher}@ 201603L // also in \libheader{functional}
581581
#define @\defnlibxname{cpp_lib_byte}@ 201603L // also in \libheader{cstddef}
582+
#define @\defnlibxname{cpp_lib_byteswap}@ 202110L // also in \libheader{bit}
582583
#define @\defnlibxname{cpp_lib_char8_t}@ 201907L
583584
// also in \libheader{atomic}, \libheader{filesystem}, \libheader{istream}, \libheader{limits}, \libheader{locale}, \libheader{ostream}, \libheader{string}, \libheader{string_view}
584585
#define @\defnlibxname{cpp_lib_chrono}@ 201907L // also in \libheader{chrono}

0 commit comments

Comments
 (0)