mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-20 19:07:01 +02:00
26 lines
686 B
C++
26 lines
686 B
C++
// SPDX-FileCopyrightText: 2014 Jannik Vogel <email@jannikvogel.de>
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <type_traits>
|
|
|
|
namespace Common {
|
|
|
|
template <typename T>
|
|
[[nodiscard]] constexpr T AlignUp(T value, std::size_t size) {
|
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
|
auto mod{static_cast<T>(value % size)};
|
|
value -= mod;
|
|
return static_cast<T>(mod == T{0} ? value : value + size);
|
|
}
|
|
|
|
template <typename T>
|
|
[[nodiscard]] constexpr T AlignDown(T value, std::size_t size) {
|
|
static_assert(std::is_unsigned_v<T>, "T must be an unsigned value.");
|
|
return static_cast<T>(value - value % size);
|
|
}
|
|
|
|
} // namespace Common
|