![]() |
General Utility Library for C++17 25.4.1
|
Bit manipulation and testing, endianness.
Typedefs | |
template<typename T > | |
using | gul17::BitFunctionReturnType = std::enable_if_t< std::is_integral< T >::value and not std::is_same< std::decay_t< T >, bool >::value, std::decay_t< T > > |
Return type of the bit manipulation functions. | |
Enumerations | |
enum class | gul17::endian { gul17::endian::little , gul17::endian::big , gul17::endian::native } |
An enum to determine the endianness of multi-byte scalars on the current platform. More... | |
Functions | |
template<typename T = unsigned, typename ReturnT = BitFunctionReturnType<T>> | |
auto constexpr | gul17::bit_set (unsigned bit) noexcept -> ReturnT |
Set a bit in an integral type. | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
auto constexpr | gul17::bit_set (T previous, unsigned bit) noexcept -> ReturnT |
Set a bit in an integral value. | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
auto constexpr | gul17::bit_reset (T previous, unsigned bit) noexcept -> ReturnT |
Reset a bit in an integral value. | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
auto constexpr | gul17::bit_flip (T previous, unsigned bit) noexcept -> ReturnT |
Flip a bit in an integral value. | |
template<typename T > | |
bool constexpr | gul17::bit_test (T bits, unsigned bit) noexcept |
Test a bit in an integral value. | |
constexpr bool | gul17::is_big_endian () |
Determine whether this platform uses big-endian (Motorola) order for storing multi-byte quantities in memory. | |
constexpr bool | gul17::is_little_endian () |
Determine whether this platform uses little-endian (Intel) order for storing multi-byte quantities in memory. | |
using gul17::BitFunctionReturnType = typedef std::enable_if_t< std::is_integral<T>::value and not std::is_same<std::decay_t<T>, bool>::value, std::decay_t<T> > |
Return type of the bit manipulation functions.
We want to SFINAE out of all types except integers. Because bools counts as integer type and we don't want that we specifically exclude it here.
The type is then simply the decayed input type, to get rid of const or volatile specifiers.
T | Type specified/deduced by bit_*() user |
|
strong |
An enum to determine the endianness of multi-byte scalars on the current platform.
In big-endian (Motorola) order, the most significant byte is stored first, followed by the other bytes in order of decreasing significance. Little-endian platforms (e.g. Intel) store the bytes in the opposite order. There are also (historical) platforms which do not conform to either of these conventions.
This is a backport of std::endian from C++20.
Enumerator | |
---|---|
little | Little-endian (e.g. Intel) |
big | Big-endian (e.g. Motorola) |
native | Native endianness. |
Flip a bit in an integral value.
Flips the bit number bit in the existing value previous. This inverts the state of the bit: setting the bit if it was previously not set and resetting the bit if it was previously set.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
References gul17::bit_set().
Reset a bit in an integral value.
Reset (clear) the bit number bit in the existing value previous.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
References gul17::bit_set().
|
inlineconstexprnoexcept |
Set a bit in an integral value.
Set the bit number bit in the existing value previous.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
References gul17::bit_set().
|
inlineconstexprnoexcept |
Set a bit in an integral type.
Return an integral value of type T where the bit number bit and only that bit is set.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
bit | Number of the bit that is to be set (LSB == 0) |
T | Type of the bit-holding integral value. |
Referenced by gul17::abs(), gul17::as_bytes(), gul17::as_writable_bytes(), gul17::SmallVector< ElementT, in_capacity >::assign(), gul17::SmallVector< ElementT, in_capacity >::assign(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::at(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::at(), gul17::SmallVector< ElementT, in_capacity >::at(), gul17::SmallVector< ElementT, in_capacity >::at(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::begin(), gul17::bit_flip(), gul17::bit_reset(), gul17::bit_set(), gul17::bit_test(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::capacity(), gul17::cat(), gul17::cat(), gul17::cat(), gul17::cat(), gul17::cat(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::cbegin(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::cend(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::change_capacity(), gul17::clamp(), gul17::clamp(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::clear(), gul17::contains(), gul17::contains(), gul17::contains_nocase(), gul17::contains_nocase(), gul17::ElementAccessor(), gul17::SmallVector< ElementT, in_capacity >::emplace(), gul17::SmallVector< ElementT, in_capacity >::emplace_back(), gul17::SmallVector< ElementT, in_capacity >::empty(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::empty(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::end(), gul17::ends_with(), gul17::ends_with(), gul17::ends_with_nocase(), gul17::ends_with_nocase(), gul17::equals_nocase(), gul17::SmallVector< ElementT, in_capacity >::erase(), gul17::SmallVector< ElementT, in_capacity >::erase(), gul17::FinalAction< F >::FinalAction(), gul17::finally(), gul17::span< ElementType, Extent >::first(), gul17::span< ElementType, Extent >::first(), gul17::gcd(), gul17::get(), gul17::ThreadPool::TaskHandle< T >::get_result(), gul17::ThreadPool::TaskHandle< T >::get_state(), gul17::hex_string(), gul17::hex_string(), gul17::hex_string(), gul17::hex_string(), gul17::hexdump(), gul17::hexdump(), gul17::hexdump_stream(), gul17::hexdump_stream(), gul17::hexdump_stream(), gul17::HexdumpParameterForward< IteratorT, ContainerT >::HexdumpParameterForward(), gul17::HexdumpParameterForward< IteratorT, ContainerT >::HexdumpParameterForward(), gul17::HexdumpParameterForward< IteratorT, ContainerT >::HexdumpParameterForward(), gul17::SmallVector< ElementT, in_capacity >::inner_capacity(), gul17::SmallVector< ElementT, in_capacity >::insert(), gul17::SmallVector< ElementT, in_capacity >::insert(), gul17::SmallVector< ElementT, in_capacity >::insert(), gul17::SmallVector< ElementT, in_capacity >::insert(), gul17::SmallVector< ElementT, in_capacity >::insert(), gul17::ThreadPool::TaskHandle< T >::is_complete(), gul17::join(), gul17::join(), gul17::join(), gul17::join(), gul17::span< ElementType, Extent >::last(), gul17::span< ElementType, Extent >::last(), gul17::lcm(), gul17::lowercase_ascii(), gul17::lowercase_ascii(), gul17::lowercase_ascii_inplace(), gul17::make_thread_pool(), gul17::maximum(), gul17::mean(), gul17::median(), gul17::null_safe_string(), gul17::null_safe_string_view(), gul17::Trigger::operator bool(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::operator<<(), gul17::Trigger::operator=(), gul17::HexdumpParameterForward< IteratorT, ContainerT >::operator=(), gul17::SmallVector< ElementT, in_capacity >::operator=(), gul17::FinalAction< F >::operator=(), gul17::HexdumpParameterForward< IteratorT, ContainerT >::operator=(), gul17::SmallVector< ElementT, in_capacity >::operator=(), gul17::SmallVector< ElementT, in_capacity >::operator=(), gul17::span< ElementType, Extent >::operator[](), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::operator[](), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::operator[](), gul17::SmallVector< ElementT, in_capacity >::operator[](), gul17::SmallVector< ElementT, in_capacity >::operator[](), gul17::SmallVector< ElementT, in_capacity >::pop_back(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::push_back(), gul17::SmallVector< ElementT, in_capacity >::push_back(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::push_back(), gul17::SmallVector< ElementT, in_capacity >::push_back(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::push_front(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::push_front(), gul17::repeat(), gul17::replace(), gul17::replace_inplace(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::reserve(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::reserve(), gul17::SmallVector< ElementT, in_capacity >::reserve(), gul17::Trigger::reset(), gul17::SlidingBuffer< ElementT, fixed_capacity, Container >::resize(), gul17::SlidingBufferExposed< ElementT, fixed_capacity, Container >::resize(), gul17::SmallVector< ElementT, in_capacity >::resize(), gul17::SmallVector< ElementT, in_capacity >::resize(), gul17::rms(), gul17::safe_string(), gul17::safe_string_view(), gul17::SmallVector< ElementT, in_capacity >::shrink_to_fit(), gul17::sleep(), gul17::sleep(), gul17::sleep(), gul17::sleep(), gul17::SmallVector< ElementT, in_capacity >::SmallVector(), gul17::SmallVector< ElementT, in_capacity >::SmallVector(), gul17::SmallVector< ElementT, in_capacity >::SmallVector(), gul17::SmallVector< ElementT, in_capacity >::SmallVector(), gul17::SmallVector< ElementT, in_capacity >::SmallVector(), gul17::split(), gul17::split(), gul17::split_sv(), gul17::starts_with(), gul17::starts_with(), gul17::starts_with_nocase(), gul17::starts_with_nocase(), gul17::span< ElementType, Extent >::subspan(), gul17::span< ElementType, Extent >::subspan(), gul17::SmallVector< ElementT, in_capacity >::swap(), gul17::swap(), gul17::to_number(), gul17::toc(), gul17::tokenize(), gul17::tokenize_sv(), gul17::Trigger::trigger(), gul17::Trigger::Trigger(), gul17::trim(), gul17::trim_left(), gul17::trim_left_sv(), gul17::trim_right(), gul17::trim_right_sv(), gul17::trim_sv(), gul17::type_name(), gul17::uppercase_ascii(), gul17::uppercase_ascii(), gul17::uppercase_ascii_inplace(), gul17::Trigger::wait(), gul17::Trigger::wait_for(), gul17::Trigger::wait_until(), gul17::within_abs(), gul17::within_orders(), and gul17::within_ulp().
Test a bit in an integral value.
Test the bit number bit in the existing value bits.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
bits | Integral value where the bit shall be tested |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
References gul17::bit_set().
Determine whether this platform uses big-endian (Motorola) order for storing multi-byte quantities in memory.
In big-endian order, the most significant byte is stored first, followed by the other bytes in order of decreasing significance.
References gul17::big, and gul17::native.
Determine whether this platform uses little-endian (Intel) order for storing multi-byte quantities in memory.
In little-endian order, the least significant byte is stored first, followed by the other bytes in order of increasing significance.
References gul17::little, and gul17::native.