22 General utilities library [utilities]

22.11 Bit manipulation [bit]

22.11.9 Permutation [bit.permute]

In the following descriptions, let N denote the value of numeric_limits<T>​::​digits, and let denote the value of the least significant bit in the base-2 representation of an integer α, so that α equals .
template<class T> constexpr T bit_reverse(T x) noexcept;
Constraints: T is an unsigned integer type ([basic.fundamental]).
Returns: reverse(x), where reverse is given by Formula 22.1, and x is x.
[Note 1: 
bit_reverse(bit_reverse(x)) equals x.
— end note]
template<class T> constexpr T bit_repeat(T x, int l);
Constraints: T is an unsigned integer type ([basic.fundamental]).
Preconditions: l is greater than zero.
Returns: , where repeat is given by Formula 22.2, x is x, and l is l.
Throws: Nothing.
Remarks: A function call expression that violates the precondition in the Preconditions: element is not a core constant expression ([expr.const.core]).
[Example 1: 
bit_repeat(uint32_t{0xc}, 4) equals 0xcccccccc.
— end example]
template<class T> constexpr T bit_compress(T x, T m) noexcept;
Constraints: T is an unsigned integer type ([basic.fundamental]).
Returns: , where compress is given by Formula 22.3, x is x, and m is m.
[Example 2: 
bit_compress(0bABCD, 0b0101) equals 0b00BD for any bits A, B, C, and D.
— end example]
template<class T> constexpr T bit_expand(T x, T m) noexcept;
Constraints: T is an unsigned integer type ([basic.fundamental]).
Returns: , where expand is given by Formula 22.4, x is x, and m is m.
[Example 3: 
bit_expand(0bABCD, 0b0101) equals 0b0C0D for any bits A, B, C, and D.
— end example]