Common: Better AlignUp implementation

This commit is contained in:
TellowKrinkle 2023-06-29 01:32:51 -05:00
parent 61c45e8d68
commit d844317a6d
1 changed files with 7 additions and 6 deletions

View File

@ -7,12 +7,6 @@
namespace Common namespace Common
{ {
template <typename T>
constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
return static_cast<T>(value + (size - value % size) % size);
}
template <typename T> template <typename T>
constexpr T AlignDown(T value, size_t size) constexpr T AlignDown(T value, size_t size)
@ -21,4 +15,11 @@ constexpr T AlignDown(T value, size_t size)
return static_cast<T>(value - value % size); return static_cast<T>(value - value % size);
} }
template <typename T>
constexpr T AlignUp(T value, size_t size)
{
static_assert(std::is_unsigned<T>(), "T must be an unsigned value.");
return AlignDown<T>(static_cast<T>(value + (size - 1)), size);
}
} // namespace Common } // namespace Common