common/alignment: Apply nodiscard and noexcept to utility functions
In all scenarios, ignoring the return value of these functions is a bug. While we're at it, we can also make them noexcept.
This commit is contained in:
@@ -8,25 +8,25 @@
|
|||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignUp(T value, std::size_t size) {
|
[[nodiscard]] constexpr T AlignUp(T value, std::size_t size) noexcept {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return static_cast<T>(value + (size - value % size) % size);
|
return static_cast<T>(value + (size - value % size) % size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr T AlignDown(T value, std::size_t size) {
|
[[nodiscard]] constexpr T AlignDown(T value, std::size_t size) noexcept {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return static_cast<T>(value - value % size);
|
return static_cast<T>(value - value % size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr bool Is4KBAligned(T value) {
|
[[nodiscard]] constexpr bool Is4KBAligned(T value) noexcept {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return (value & 0xFFF) == 0;
|
return (value & 0xFFF) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr bool IsWordAligned(T value) {
|
[[nodiscard]] constexpr bool IsWordAligned(T value) noexcept {
|
||||||
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
||||||
return (value & 0b11) == 0;
|
return (value & 0b11) == 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user