header_utils
Loading...
Searching...
No Matches
Bits

Types and functions for retrieving and manipulating bits in integral values. More...

Concepts

concept  ghassanpl::bit_integral
 Whether or not a type is integral (but not a bool).
 

Classes

struct  ghassanpl::bit_view< INTEGER_TYPE >
 A view over an integral value allowing for iteration and modification of its individual bits. More...
 
struct  ghassanpl::bit_reference< VALUE_TYPE, BIT_NUM >
 Models a reference to a specific bit in a variable. Can be a statically-defined bit number (BIT_NUM != dynamic_bit_number) More...
 

Typedefs

template<size_t N>
using ghassanpl::uintN_t = typename detail::uintN_t_t< N >::value
 An unsigned integer type for the given PoT bit size.
 
template<size_t N>
using ghassanpl::intN_t = typename detail::intN_t_t< N >::value
 An integer type for the given PoT bit size.
 
template<bool SIGNED, size_t N>
using ghassanpl::sintN_t = typename detail::sintN_t_t< SIGNED, N >::value
 A signed integer type for the given PoT bit size.
 

Functions

template<std::ranges::contiguous_range RANGE_TYPE>
 ghassanpl::bit_view (RANGE_TYPE &T) -> bit_view< std::ranges::range_value_t< std::decay_t< decltype(T)> > >
 
template<std::ranges::contiguous_range RANGE_TYPE>
 ghassanpl::bit_view (RANGE_TYPE const &T) -> bit_view< std::ranges::range_value_t< std::decay_t< decltype(T)> > const >
 
template<std::ranges::contiguous_range RANGE_TYPE>
auto ghassanpl::make_bit_reference (RANGE_TYPE &&range, size_t bit_num)
 
template<size_t BIT_NUM, std::ranges::contiguous_range RANGE_TYPE>
auto ghassanpl::make_bit_reference (RANGE_TYPE &&range)
 
template<bit_integral VALUE_TYPE>
auto ghassanpl::make_bit_reference (VALUE_TYPE &value, size_t bit_num)
 
template<size_t BIT_NUM, bit_integral VALUE_TYPE>
auto ghassanpl::make_bit_reference (VALUE_TYPE &value)
 
template<bit_integral T>
constexpr auto ghassanpl::most_significant_half (T v) noexcept
 Returns an integer with the N/2 most significant bits of the given N-bit integer.
 
template<bit_integral T>
constexpr auto ghassanpl::least_significant_half (T v) noexcept
 Returns an integer with the N/2 least significant bits of the given N-bit integer.
 

Variables

template<typename T >
constexpr auto ghassanpl::bit_count
 Equal to the number of bits in the type.
 
constexpr uint64_t ghassanpl::all_bits
 A value of type uint64_t with all bits set.
 
template<size_t BEGIN, size_t END>
constexpr uint64_t ghassanpl::bit_mask_v
 Value with bits between BEGIN and END (exclusive) set.
 
template<bit_integral FOR>
constexpr uint64_t ghassanpl::bit_mask_for_v
 Value with all bits available for the FOR type set (e.g. first 8 bits for uint8_t will be set, etc.)
 
constexpr size_t ghassanpl::dynamic_bit_number
 Used to specify that a ghassanpl::bit_reference references a bit number given at runtime.
 

Endianness

template<bit_integral B>
constexpr B ghassanpl::to_big_endian (B val) noexcept
 Returns val in its big-endian representation.
 
template<bit_integral B>
constexpr B ghassanpl::to_little_endian (B val) noexcept
 Returns val in its big-endian representation.
 
template<std::endian ENDIANNESS, bit_integral B>
constexpr B ghassanpl::to_endian (B val) noexcept
 Returns val in its ENDIANNESS representation.
 
template<bit_integral B>
constexpr B ghassanpl::to_endian (B val, std::endian endianness) noexcept
 Returns val in its endianness representation.
 

Detailed Description

Types and functions for retrieving and manipulating bits in integral values.

Typedef Documentation

◆ intN_t

template<size_t N>
using ghassanpl::intN_t = typedef typename detail::intN_t_t<N>::value

An integer type for the given PoT bit size.

Definition at line 80 of file bits.h.

◆ sintN_t

template<bool SIGNED, size_t N>
using ghassanpl::sintN_t = typedef typename detail::sintN_t_t<SIGNED, N>::value

A signed integer type for the given PoT bit size.

Definition at line 92 of file bits.h.

◆ uintN_t

template<size_t N>
using ghassanpl::uintN_t = typedef typename detail::uintN_t_t<N>::value

An unsigned integer type for the given PoT bit size.

Definition at line 67 of file bits.h.

Function Documentation

◆ least_significant_half()

template<bit_integral T>
constexpr auto ghassanpl::least_significant_half ( v)
constexprnoexcept

Returns an integer with the N/2 least significant bits of the given N-bit integer.

Definition at line 105 of file bits.h.

◆ make_bit_reference() [1/4]

template<size_t BIT_NUM, std::ranges::contiguous_range RANGE_TYPE>
auto ghassanpl::make_bit_reference ( RANGE_TYPE &&  range)

Definition at line 223 of file bit_view.h.

◆ make_bit_reference() [2/4]

template<std::ranges::contiguous_range RANGE_TYPE>
auto ghassanpl::make_bit_reference ( RANGE_TYPE &&  range,
size_t  bit_num 
)

Definition at line 216 of file bit_view.h.

◆ make_bit_reference() [3/4]

template<size_t BIT_NUM, bit_integral VALUE_TYPE>
auto ghassanpl::make_bit_reference ( VALUE_TYPE &  value)

Definition at line 236 of file bit_view.h.

◆ make_bit_reference() [4/4]

template<bit_integral VALUE_TYPE>
auto ghassanpl::make_bit_reference ( VALUE_TYPE &  value,
size_t  bit_num 
)

Definition at line 230 of file bit_view.h.

◆ most_significant_half()

template<bit_integral T>
constexpr auto ghassanpl::most_significant_half ( v)
constexprnoexcept

Returns an integer with the N/2 most significant bits of the given N-bit integer.

Definition at line 96 of file bits.h.

◆ to_big_endian()

template<bit_integral B>
constexpr B ghassanpl::to_big_endian ( B  val)
constexprnoexcept

Returns val in its big-endian representation.

Definition at line 117 of file bits.h.

◆ to_endian() [1/2]

template<std::endian ENDIANNESS, bit_integral B>
constexpr B ghassanpl::to_endian ( B  val)
constexprnoexcept

Returns val in its ENDIANNESS representation.

Definition at line 125 of file bits.h.

◆ to_endian() [2/2]

template<bit_integral B>
constexpr B ghassanpl::to_endian ( B  val,
std::endian  endianness 
)
constexprnoexcept

Returns val in its endianness representation.

Definition at line 129 of file bits.h.

◆ to_little_endian()

template<bit_integral B>
constexpr B ghassanpl::to_little_endian ( B  val)
constexprnoexcept

Returns val in its big-endian representation.

Definition at line 121 of file bits.h.

Variable Documentation

◆ all_bits

constexpr uint64_t ghassanpl::all_bits
inlineconstexpr

A value of type uint64_t with all bits set.

Definition at line 36 of file bits.h.

◆ bit_count

template<typename T >
constexpr auto ghassanpl::bit_count
inlineconstexpr

Equal to the number of bits in the type.

Definition at line 33 of file bits.h.

◆ bit_mask_for_v

template<bit_integral FOR>
constexpr uint64_t ghassanpl::bit_mask_for_v
inlineconstexpr

Value with all bits available for the FOR type set (e.g. first 8 bits for uint8_t will be set, etc.)

Definition at line 44 of file bits.h.

◆ bit_mask_v

template<size_t BEGIN, size_t END>
constexpr uint64_t ghassanpl::bit_mask_v
inlineconstexpr

Value with bits between BEGIN and END (exclusive) set.

Definition at line 40 of file bits.h.

◆ dynamic_bit_number

constexpr size_t ghassanpl::dynamic_bit_number
inlineconstexpr

Used to specify that a ghassanpl::bit_reference references a bit number given at runtime.

Definition at line 134 of file bits.h.