diff --git a/luna/Alignment.h b/luna/Alignment.h index e69c0aad..0721aae5 100644 --- a/luna/Alignment.h +++ b/luna/Alignment.h @@ -36,4 +36,11 @@ template constexpr T get_blocks_from_size(T value, T block_size) static_assert(get_blocks_from_size(40960, 4096) == 10); static_assert(get_blocks_from_size(194, 64) == 4); static_assert(get_blocks_from_size(2, 32) == 1); -static_assert(get_blocks_from_size(0, 256) == 0); \ No newline at end of file +static_assert(get_blocks_from_size(0, 256) == 0); + +// Offset a pointer by exactly bytes, no matter the type. Useful to avoid the quirks that come from C pointer +// arithmetic. +template constexpr T* offset_ptr(T* ptr, Offset offset) +{ + return (T*)((char*)ptr + offset); +} \ No newline at end of file