Use TypeTraits in Alignment.h to make static assertions more readable
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-17 13:50:27 +01:00
parent ace674e518
commit acb0ab1cd7
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include <luna/TypeTraits.h>
// Must ALWAYS be called with a power of two as alignment. // Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T is_aligned(T value) 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); 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. // Must ALWAYS be called with a power of two as alignment.
template <usize alignment, typename T> constexpr T align_down(T value) 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; return value - value % alignment;
} }