Provides constexpr bit counting functions. More...
#include <cstdint>#include <type_traits>#include <utility>#include "ugmisc/features.hpp"#include "ugmisc/sfinae_helpers.hpp"Go to the source code of this file.
Functions | |
| template<class T> | |
| constexpr auto | ugmisc::clz (T) noexcept -> UGMISC_BITWISE_UINT_RETURN(T, int) |
| template<class T> | |
| constexpr auto | ugmisc::cl1 (T) noexcept -> UGMISC_BITWISE_UINT_RETURN(T, int) |
| template<class T> | |
| constexpr auto | ugmisc::crz (T) noexcept -> UGMISC_BITWISE_UINT_RETURN(T, int) |
| template<class T> | |
| constexpr auto | ugmisc::cr1 (T) noexcept -> UGMISC_BITWISE_UINT_RETURN(T, int) |
| template<class T> | |
| constexpr auto | ugmisc::bitwidth (T) noexcept -> UGMISC_BITWISE_UINT_RETURN(T, int) |
Provides constexpr bit counting functions.
If features.hpp claims that we have the std library bit counting functions, we use those.
If not we use a series of bitwise logic ops to home in on the place where the first set bit is, or last set bit or whatever.
Even if the standard bit op functions are available, UgMisc will fall back to its own implementation if the standard functions don't accept an otherwise suitable type. UgMisc determines a type is suitable depending on the type's specialisation of std::numeric_limits and whether certain expressions are valid.
TBD: Should the clz function and its relatives be renamed to match the standard functions' names? Probably.
|
constexprnoexcept |
Counts bits needed to represent the value. Simply forwards to std::bit_width if that is available, or provides its own implementation otherwise.
|
constexprnoexcept |
Counts left one bits. Simply forwards the call to std::countl_one if that is available, or provides its own implementation otherwise.
|
constexprnoexcept |
Counts left zero bits. Simply forwards the call to std::countl_zero if that is available, or provides its own implementation otherwise.
|
constexprnoexcept |
Counts right one-bits. Simply forwards the call to std::countr_one if that is available, or provides its own implementation otherwise.
|
constexprnoexcept |
Counts right zero bits. Simply forwards the call to std::countr_zero if that is available, or provides its own implementation otherwise.