30 template<std::
integral T>
31 [[nodiscard]]
constexpr T
Byteswap(T value)
noexcept
33#if defined(__cpp_lib_byteswap) && __cpp_lib_byteswap >= 202110L
34 return std::byteswap(value);
36 static_assert(std::has_unique_object_representations_v<T>,
"T may not have padding bits");
37 auto value_representation = std::bit_cast<std::array<std::byte,
sizeof(T)>>(value);
38 std::ranges::reverse(value_representation);
39 return std::bit_cast<T>(value_representation);
43 template <
class T>
requires (std::unsigned_integral<T>)
44 [[nodiscard]]
constexpr int MSBIndex(T n)
noexcept
48 return std::numeric_limits<T>::digits - std::countl_zero(n) - 1;
51 template<std::
integral T>
54 return (n + T(3)) & ~T(3);
57 template<std::
integral T>
58 [[nodiscard]]
constexpr std::size_t
BitWidthOf() noexcept {
return sizeof(T) * CHAR_BIT; }
Definition AcousticMaterial.h:36
constexpr int MSBIndex(T n) noexcept
Definition Bits.h:44
constexpr T Byteswap(T value) noexcept
Definition Bits.h:31
constexpr T RoundUpBy4(T n) noexcept
Definition Bits.h:52
constexpr std::size_t BitWidthOf() noexcept
Definition Bits.h:58