#ifndef MYGRATE_HELPERS_H #define MYGRATE_HELPERS_H #include #include #include #include #include #include namespace MyGrate { template using SmallestUInt = std::conditional_t>>; template constexpr inline auto bitslice(const std::integral auto i, uint8_t offset) -> SmallestUInt { return (i >> offset) & ((1U << size) - 1U); } template constexpr inline auto verify(R expr, P &&... p) { if (!expr) [[unlikely]] { throw X(std::forward

(p)...); } return expr; } constexpr inline auto mod100_extract(std::integral auto & i) { using R = std::conditional_t, int8_t, uint8_t>; const auto r {boost::numeric_cast(i % 100)}; i /= 100; return r; } template concept Stringable = requires(T a) { { std::to_string(a) } -> std::same_as; }; template concept Viewable = requires(T a) { { a.data() } -> std::convertible_to; { a.size() } -> std::integral; }; inline const char * getenv(const char * env, const char * dfl) { if (const auto e {::getenv(env)}) { return e; } return dfl; } } #endif