9template <auto Start, auto End, auto Inc,
class F>
10constexpr void constexpr_for(F&& f) {
11 if constexpr (Start < End) {
12 f.template operator()<Start>();
13 constexpr_for<Start + Inc, End, Inc>(f);
20template <enumeration Enum>
21constexpr std::underlying_type_t<Enum> to_underlying(Enum e)
noexcept {
22 return static_cast<std::underlying_type_t<Enum>
>(e);
28template <std::
size_t n,
typename T =
int32_t>
29constexpr T bit = T{1} << n;
37template <std::
size_t w
idth,
typename T =
int32_t>
38constexpr T bit_value = bit<width - 1, T>;
46template <std::
size_t w
idth,
typename T =
int32_t>
47constexpr T bitmask = bit<width, T> - 1;
50constexpr T bit_from_top(
const std::size_t n) {
51 return T{1} << (std::numeric_limits<T>::digits - (n + 1));
55constexpr T top_n_bits(
const std::size_t n) {
57 for (std::size_t i = 0; i < n; i++) {
58 output |= bit_from_top<T>(i);
64constexpr T top_bit = T{1} << (std::numeric_limits<T>::digits - 1);
66template <std::
integral T>
67constexpr T median_value = (std::numeric_limits<T>::max() / 2) + (std::numeric_limits<T>::min() / 2) + 1;
70constexpr T set_top_bit(
const T v) {
71 return v | top_bit<T>;
74template <
typename T, std::
size_t n>
75constexpr T set_top_n_bits(
const T v) {
77 for (std::size_t i = 0; i < n; i++) {
78 output |= bit_from_top<T>(i);
84[[nodiscard]]
constexpr T map(T x, T in_min, T in_max, T out_min, T out_max) {
85 return out_min + ((x - in_min) * (out_max - out_min)) / (in_max - in_min);
92template <std::
integral T>
93[[nodiscard]]
constexpr T div_ceil(T a, T b) {
94 return (a + (b - 1)) / b;
100[[nodiscard]]
constexpr bool infinite_a_lt_b(uint32_t a, uint32_t b) {
101 return ((int32_t)(a - b) < 0);
107consteval uint_least64_t
operator"" _u64(
unsigned long long arg) {
110consteval uint_least32_t
operator"" _u32(
unsigned long long arg) {
113consteval uint_least16_t
operator"" _u16(
unsigned long long arg) {
116consteval uint_least8_t
operator"" _u8(
unsigned long long arg) {
121consteval int_least64_t
operator"" _i64(
unsigned long long arg) {
124consteval int_least32_t
operator"" _i32(
unsigned long long arg) {
127consteval int_least16_t
operator"" _i16(
unsigned long long arg) {
130consteval int_least8_t
operator"" _i8(
unsigned long long arg) {
134consteval std::byte
operator"" _b(
unsigned long long arg) {
135 return std::byte(arg);