Use TypeTraits in Alignment.h to make static assertions more readable
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ace674e518
commit
acb0ab1cd7
@ -1,9 +1,10 @@
|
||||
#pragma once
|
||||
#include <luna/TypeTraits.h>
|
||||
|
||||
// Must ALWAYS be called with a power of two as alignment.
|
||||
template <usize alignment, typename T> constexpr T is_aligned(T value)
|
||||
{
|
||||
static_assert((alignment & (alignment - 1)) == 0);
|
||||
static_assert(IsPowerOfTwo<usize, alignment>);
|
||||
return (value % alignment == 0);
|
||||
}
|
||||
|
||||
@ -14,7 +15,7 @@ static_assert(is_aligned<4096>(40960u));
|
||||
// Must ALWAYS be called with a power of two as alignment.
|
||||
template <usize alignment, typename T> constexpr T align_down(T value)
|
||||
{
|
||||
static_assert((alignment & (alignment - 1)) == 0);
|
||||
static_assert(IsPowerOfTwo<usize, alignment>);
|
||||
return value - value % alignment;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user