Skip to content

Commit

Permalink
cleanup bit_reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
CrustyAuklet committed Sep 21, 2021
1 parent 1946598 commit b12b022
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/bitpacker/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ namespace bitpacker {

/// reverses the bits in the value `val`.
template<typename T, size_type BitSize>
constexpr auto reverse_bits(std::remove_cv_t<T> val) noexcept {
using val_type = std::remove_reference_t<std::remove_cv_t<T>>;
static_assert(std::is_integral<val_type>::value, "bitpacker::reverse_bits: val needs to be an integral type");
using underlying_type = unsigned_type<sizeof(val_type) * ByteSize>;
val_type retval = val;
return reverse_bits<underlying_type>(static_cast<underlying_type>(retval)) >> (sizeof(underlying_type) * ByteSize - BitSize);
constexpr auto reverse_bits(const typename std::remove_cv<typename std::remove_reference<T>::type>::type val) noexcept {
using arg_type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
using underlying_type = unsigned_type<sizeof(arg_type) * ByteSize>;
static_assert(std::is_integral<arg_type>::value, "bitpacker::reverse_bits: val needs to be an integral type");
return reverse_bits<underlying_type>(static_cast<underlying_type>(val)) >> (sizeof(underlying_type) * ByteSize - BitSize);
}

constexpr uint8_t byte_swap(const std::uint8_t v) {
return v;
Expand Down

0 comments on commit b12b022

Please sign in to comment.