From acb0ab1cd7796457b9d2931dfc32976851dc91a0 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 17 Dec 2022 13:50:27 +0100 Subject: [PATCH] Use TypeTraits in Alignment.h to make static assertions more readable --- luna/include/luna/Alignment.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/luna/include/luna/Alignment.h b/luna/include/luna/Alignment.h index 90fa632a..02e04d92 100644 --- a/luna/include/luna/Alignment.h +++ b/luna/include/luna/Alignment.h @@ -1,9 +1,10 @@ #pragma once +#include // Must ALWAYS be called with a power of two as alignment. template constexpr T is_aligned(T value) { - static_assert((alignment & (alignment - 1)) == 0); + static_assert(IsPowerOfTwo); 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 constexpr T align_down(T value) { - static_assert((alignment & (alignment - 1)) == 0); + static_assert(IsPowerOfTwo); return value - value % alignment; }