rll/bit.h file

Namespaces

namespace rll
Contract-programming related functions and classes.

Enums

enum class endian: signed int { little = 0, big = 1, native = little }
Endianness.

Functions

template <class To, class From>
bit_cast(From const& src) noexcept
Casts value from one type to another by bit copy.
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
auto bit_ceil(T x) →  T constexpr noexcept
Returns the next power of two of the value.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto byteswap(T x) →  T constexpr noexcept
Reverses the byte order of the value.
template <typename T>
auto byteswap_unchecked(T u) →  T noexcept
Reverses the byte order of the value without checking for unique object representations.
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto has_single_bit(T x) →  bool constexpr noexcept
Checks if the value is an integral power of two.
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto is_pow2(T x) →  bool constexpr noexcept
Checks if the value is an integral power of two.
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto popcount(T x) →  int constexpr noexcept
Returns the number of 1 bits in the value.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_big_endian(T x) →  T constexpr noexcept
Reverses the byte order of the value if the native endianness is little.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_little_endian(T x) →  T constexpr noexcept
Reverses the byte order of the value if the native endianness is big.

Defines

#define RLL_BIG_ENDIAN
#define RLL_LITTLE_ENDIAN
#define ___rolly_byteswap16
#define ___rolly_byteswap32
#define ___rolly_byteswap64