diff --git a/source/numerics.tex b/source/numerics.tex index 23a78fd258..3dbad178de 100644 --- a/source/numerics.tex +++ b/source/numerics.tex @@ -1290,6 +1290,10 @@ template constexpr To bit_cast(const From& from) noexcept; + // \ref{bit.byteswap}, \tcode{byteswap} + template + constexpr T byteswap(T value) noexcept; + // \ref{bit.pow.two}, integral powers of 2 template constexpr bool has_single_bit(T x) noexcept; @@ -1355,6 +1359,15 @@ if there is no value of the object's type corresponding to the value representation produced, the behavior is undefined. If there are multiple such values, which value is produced is unspecified. +A bit in the value representation of the result is indeterminate if +it does not correspond to a bit in the value representation of \tcode{from} or +corresponds to a bit of an object that is not within its lifetime or +has an indeterminate value\iref{basic.indet}. +For each bit in the value representation of the result that is indeterminate, +the smallest object containing that bit has an indeterminate value; +the behavior is undefined unless that object is +of unsigned ordinary character type or \tcode{std::byte} type. +The result does not otherwise contain any indeterminate values. \pnum \remarks @@ -1370,6 +1383,34 @@ \end{itemize} \end{itemdescr} +\rSec2[bit.byteswap]{\tcode{byteswap}} + +\indexlibraryglobal{byteswap}% +\begin{itemdecl} +template + constexpr T byteswap(T value) noexcept; +\end{itemdecl} + +\begin{itemdescr} +\pnum +\constraints +\tcode{T} models \libconcept{integral}. + +\pnum +\mandates +\tcode{T} does not have padding bits\iref{basic.types.general}. + +\pnum +Let the sequence $R$ comprise +the bytes of the object representation of \tcode{value} in reverse order. + +\pnum +\returns +An object \tcode{v} of type \tcode{T} +such that each byte in the object representation of \tcode{v} is equal to +the byte in the corresponding position in $R$. +\end{itemdescr} + \rSec2[bit.pow.two]{Integral powers of 2} \indexlibraryglobal{has_single_bit}% diff --git a/source/support.tex b/source/support.tex index fcb883bf1e..efd0b7ebc6 100644 --- a/source/support.tex +++ b/source/support.tex @@ -579,6 +579,7 @@ #define @\defnlibxname{cpp_lib_bounded_array_traits}@ 201902L // also in \libheader{type_traits} #define @\defnlibxname{cpp_lib_boyer_moore_searcher}@ 201603L // also in \libheader{functional} #define @\defnlibxname{cpp_lib_byte}@ 201603L // also in \libheader{cstddef} +#define @\defnlibxname{cpp_lib_byteswap}@ 202110L // also in \libheader{bit} #define @\defnlibxname{cpp_lib_char8_t}@ 201907L // also in \libheader{atomic}, \libheader{filesystem}, \libheader{istream}, \libheader{limits}, \libheader{locale}, \libheader{ostream}, \libheader{string}, \libheader{string_view} #define @\defnlibxname{cpp_lib_chrono}@ 201907L // also in \libheader{chrono}