#pragma once #pragma once #include "CoreTypes.h" #include "Templates/TypeTraits.h" NS_REDCRAFT_BEGIN NS_BEGIN(Memory) template FORCEINLINE constexpr T Align(T Val, uint64 Alignment) { static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "Align expects an integer or pointer type"); return (T)(((uint64)Val + Alignment - 1) & ~(Alignment - 1)); } template FORCEINLINE constexpr T AlignDown(T Val, uint64 Alignment) { static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "AlignDown expects an integer or pointer type"); return (T)(((uint64)Val) & ~(Alignment - 1)); } template FORCEINLINE constexpr bool IsAligned(T Val, uint64 Alignment) { static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "IsAligned expects an integer or pointer type"); return !((uint64)Val & (Alignment - 1)); } template FORCEINLINE constexpr T AlignArbitrary(T Val, uint64 Alignment) { static_assert(TypeTraits::TIsIntegral::Value || TypeTraits::TIsPointer::Value, "AlignArbitrary expects an integer or pointer type"); return (T)((((uint64)Val + Alignment - 1) / Alignment) * Alignment); } NS_END(Memory) NS_REDCRAFT_END