1 #ifndef cetlib_bit_manipulation_h 2 #define cetlib_bit_manipulation_h 12 #include <type_traits> 17 template <
class U,
bool = std::is_
unsigned_v<U>>
22 static constexpr std::size_t
value = std::numeric_limits<U>::digits;
29 template <
class U, std::
size_t n,
bool = n<bit_size_v<U>> struct bit_number;
31 template <
class U, std::
size_t n>
32 struct bit_number<U, n, true> {
33 static constexpr std::size_t
value = U(1u) <<
n;
36 template <
class U, std::
size_t n>
37 struct bit_number<U, n, false> {
38 static constexpr std::size_t
value = U(0u);
41 template <
class U, std::
size_t n>
47 bool = std::is_unsigned_v<U>,
48 bool = (n + 1) < bit_size_v<U>>
51 template <
class U, std::
size_t n>
52 struct right_bits<U, n, true, true> {
53 static constexpr U
value = bit_number_v<U, n + 1> -
static_cast<U
>(1u);
56 template <
class U, std::
size_t n>
57 struct right_bits<U, n, true, false> {
58 static constexpr U
value = ~0u;
61 template <
class U, std::
size_t n>
67 bool = std::is_unsigned_v<U>,
71 template <
class U, std::
size_t n>
72 struct left_bits<U, n, true, true> {
74 static constexpr U n_zeros = bit_size_v<U> -
n;
77 static constexpr U
value = ~right_bits_v<U, n_zeros>;
80 template <
class U, std::
size_t n>
81 struct left_bits<U, n, true, false> {
82 static constexpr U
value = U(-1);
87 inline constexpr std::enable_if_t<std::is_unsigned_v<U>, U>
90 constexpr std::size_t nbits = bit_size_v<U>;
91 constexpr std::size_t
mask = nbits - 1ul;
93 return (X << n) | (X >> (nbits -
n) & mask);
constexpr std::size_t bit_size_v