diff --git a/include/support.h b/include/support.h index e75fc514..cfa8cf23 100644 --- a/include/support.h +++ b/include/support.h @@ -38,6 +38,15 @@ // Works with both \ and / directory delimeters. std::string get_basename(const std::string& filename); +// Unsigned integer division with ceiling +// There is no risk of signed types being used here because the template is unsigned +template::value>::type, + typename T2, class = typename std::enable_if::value>::type> +inline const T1 ceil_divide(const T1 x, const T2 y) noexcept { + return (x != 0) ? 1 + ((x - 1) / y) : 0; + // https://stackoverflow.com/a/2745086 +} + // Include a message in assert, similar to static_assert: #define assertm(exp, msg) assert(((void)msg, exp)) // Use (void) to silent unused warnings.