mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 21:07:52 +00:00
common: alignment: Add a helper function for generic alignment checking.
This commit is contained in:
parent
ad48ebb2c8
commit
b838e58d63
1 changed files with 7 additions and 0 deletions
|
@ -38,6 +38,13 @@ constexpr bool IsWordAligned(T value) {
|
||||||
return (value & 0b11) == 0;
|
return (value & 0b11) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool IsAligned(T value, std::size_t alignment) {
|
||||||
|
using U = typename std::make_unsigned<T>::type;
|
||||||
|
const U mask = static_cast<U>(alignment - 1);
|
||||||
|
return (value & mask) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t Align = 16>
|
template <typename T, std::size_t Align = 16>
|
||||||
class AlignmentAllocator {
|
class AlignmentAllocator {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue