/** * @file Common.h * @author apio (cloudapio.eu) * @brief Common utility functions. * * @copyright Copyright (c) 2023, the Luna authors. * */ #pragma once /** * @brief Divide a by b, rounding the quotient up to the next multiple of b. * * @tparam T The type of a and b. * @param a The dividend. * @param b The divisor. * @return constexpr T The result of the operation. */ template inline constexpr T ceil_div(T a, T b) { return (a + (b - 1)) / b; } /** * @brief Return the minimum value out of a set of arguments. * * @tparam T The type of the arguments. * @param a The first value of the set of arguments. * @param args The rest of the set of arguments. * @return constexpr T The minimum value. */ template inline constexpr T min(T a, Args... args) { if constexpr (sizeof...(args) == 0) return a; else { T b = min(args...); return a > b ? b : a; } } /** * @brief Return the maximum value out of a set of arguments. * * @tparam T The type of the arguments. * @param a The first value of the set of arguments. * @param args The rest of the set of arguments. * @return constexpr T The maximum value. */ template inline constexpr T max(T a, Args... args) { if constexpr (sizeof...(args) == 0) return a; else { T b = max(args...); return a > b ? a : b; } }