Miscellaneous utility functions and classes.
More...
#include <cdefs.h>
#include <limits>
#include <stddef.h>
#include <stdint.h>
#include <type_traits>
#include <utility>
Go to the source code of this file.
|
| constexpr size_t | utils::bytes_to_bits (size_t in) |
| | Turn a byte count into a bit count.
|
| template<size_t N> |
| constexpr size_t | utils::log2 () |
| | Compute the log base 2 of a power of 2.
|
| template<> |
| constexpr size_t | utils::log2< 1U > () |
| template<typename T, size_t N> |
| constexpr size_t | utils::array_size (T(&a)[N]) |
| | Return the extent of an array.
|
template<typename T>
requires std::is_integral_v<T> |
| constexpr T | utils::round_up_divide (T value, T divisor) |
| | Divide value by divisor, rounding up, unlike /.
|
template<typename T>
requires std::is_integral_v<T> |
| constexpr T | utils::align_up (T value, T multiple) |
| | Return the smallest multiple greater than or equal to value.
|
template<auto Multiple, typename T>
requires std::is_integral_v<T> && (std::in_range<T>(Multiple)) && ((Multiple & (Multiple - 1)) == 0) |
| constexpr T | utils::align_up (T value) |
| | Return the smallest Multiple greater than or equal to value, for the special case where Multiple is a static power of two.
|
Miscellaneous utility functions and classes.
Definition in file utils.hh.
◆ align_up() [1/2]
template<auto Multiple, typename T>
requires std::is_integral_v<T> && (std::in_range<T>(Multiple)) && ((Multiple & (Multiple - 1)) == 0)
| T utils::align_up |
( |
T | value | ) |
|
|
constexpr |
Return the smallest Multiple greater than or equal to value, for the special case where Multiple is a static power of two.
If value + Multiple overflows the type T, the result is correct in a modular sense, but likely not useful in practice.
Definition at line 87 of file utils.hh.
◆ align_up() [2/2]
template<typename T>
requires std::is_integral_v<T>
| T utils::align_up |
( |
T | value, |
|
|
T | multiple ) |
|
constexpr |
Return the smallest multiple greater than or equal to value.
If value + multiple overflows their type T, the result is correct in a modular sense, but likely not useful in practice.
Definition at line 69 of file utils.hh.
◆ array_size()
template<typename T, size_t N>
| size_t utils::array_size |
( |
T(&) | a[N] | ) |
|
|
constexpr |
Return the extent of an array.
Definition at line 43 of file utils.hh.
◆ bytes_to_bits()
| size_t utils::bytes_to_bits |
( |
size_t | in | ) |
|
|
constexpr |
Turn a byte count into a bit count.
Definition at line 21 of file utils.hh.
◆ log2()
Compute the log base 2 of a power of 2.
Definition at line 28 of file utils.hh.
◆ log2< 1U >()
◆ round_up_divide()
template<typename T>
requires std::is_integral_v<T>
| T utils::round_up_divide |
( |
T | value, |
|
|
T | divisor ) |
|
constexpr |
Divide value by divisor, rounding up, unlike /.
If value + divisor overflows their type T, the result is correct in a modular sense, but likely not useful in practice.
Definition at line 56 of file utils.hh.