Common: Better AlignUp implementation
This commit is contained in:
parent
61c45e8d68
commit
d844317a6d
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue