@@ -6,6 +6,26 @@ provides an implementation that mirrors
66https://en.cppreference.com/w/cpp/header/bit[`<bit>`], but is
77`constexpr` in C++17. It is mostly based on intrinsics.
88
9+ === `bit_destructure`
10+
11+ `bit_destructure` is a function for unpacking an unsigned integral value into multiple
12+ smaller bit width values. It is a more general case of xref:bit.adoc#_bit_unpack[`bit_unpack`].
13+
14+ [source,cpp]
15+ ----
16+ auto const [a, b, c] = stdx::bit_destructure<8, 24>(0x1234'5678u);
17+ assert(a == 0x78u); // bits [0-8)
18+ assert(b == 0x3456u); // bits [8-24)
19+ assert(c == 0x12u); // bits [24-32)
20+ ----
21+
22+ The `value_type` of the returned array is the same as the type of the value that
23+ is pass to `bit_destructure`.
24+
25+ NOTE: Unlike `bit_unpack`, `bit_destructure` returns the elements in
26+ _increasing_ order of significance, and the template arguments representing the
27+ split boundaries must be in increasing order.
28+
929=== `bit_mask`
1030
1131`bit_mask` is a function for constructing a bit mask between most-significant
@@ -71,7 +91,7 @@ static_assert(y == x);
7191- to pack 4 `std::uint16_t`s into a `std::uint64_t`
7292- to pack 8 `std::uint8_t`s into a `std::uint64_t`
7393
74- The arguments are listed in order of significance, i.e. for the binary
94+ The arguments are listed in order of _decreasing_ significance, i.e. for the binary
7595overloads, the first argument is the high bits, and the second argument the low
7696bits.
7797
@@ -109,7 +129,7 @@ assert(b == 0x5678u);
109129- to unpack a `std::uint64_t` into 8 `std::uint8_t`s
110130
111131The return value of `bit_unpack` is actually a `std::array` with elements in
112- order of significance. In this way `bit_unpack` followed by `bit_pack` produces
132+ order of _decreasing_ significance. In this way `bit_unpack` followed by `bit_pack` produces
113133the original value.
114134
115135[source,cpp]
0 commit comments