16 #include <meta/meta.hpp> 22 #if __has_include(<endian.h>) // unix GLIBC 24 #elif __has_include(<sys/endian.h>) // *BSD 25 #include <sys/endian.h> 26 #endif // __has_include(endian.h) 40 template <
typename type_t>
41 constexpr
auto sizeof_bits = min_viable_uint_v<CHAR_BIT * sizeof(type_t)>;
52 constexpr
bool is_power_of_two(
size_t const n)
54 return n > 0 && (n & (n-1)) == 0;
68 constexpr
size_t next_power_of_two(
size_t n)
74 for (
size_t shift = 1; !is_power_of_two(n + 1); shift <<= 1)
89 template <std::Un
signedIntegral
unsigned_t>
90 constexpr uint8_t bit_scan_reverse(unsigned_t n)
94 if constexpr (
sizeof(unsigned_t) ==
sizeof(
unsigned long long))
95 return sizeof_bits<unsigned long long> - __builtin_clzll(n) - 1;
96 else if constexpr (
sizeof(unsigned_t) ==
sizeof(
unsigned long))
97 return sizeof_bits<unsigned long> - __builtin_clzl(n) - 1;
99 return sizeof_bits<unsigned> - __builtin_clz(n) - 1;
102 for (; n != 0; n >>= 1, ++i);
119 template <std::Integral type>
120 constexpr type to_little_endian(type
const in) noexcept
122 if constexpr (endian::native == endian::little)
126 else if constexpr (endian::native == endian::big)
128 static_assert(
sizeof(type) <= 8,
129 "Can only convert the byte encoding for integral numbers with a size of up to 8 bytes.");
130 static_assert(is_power_of_two(
sizeof(type)),
131 "Can only convert the byte encoding for integral numbers whose byte size is a power of two.");
133 if constexpr (
sizeof(type) == 2)
135 else if constexpr (sizeof(type) == 4)
137 else if constexpr (sizeof(type) == 8)
144 static_assert(endian::native == endian::little || endian::native == endian::big,
145 "Expected a little-endian or big-endian platform.");
Provides metaprogramming utilities for integer types.
Provides seqan3::detail::endian.
Definition: aligned_sequence_concept.hpp:35