Simplify utils::align() a bit
std::is_unsigned implies std::is_integral I believe.
This commit is contained in:
+6
-6
@@ -366,24 +366,24 @@ namespace utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Align to power of 2
|
// Align to power of 2
|
||||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value>>
|
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||||
constexpr T align(T value, ullong align)
|
constexpr T align(T value, std::type_identity_t<T> align)
|
||||||
{
|
{
|
||||||
return static_cast<T>((value + (align - 1)) & (0 - align));
|
return static_cast<T>((value + (align - 1)) & (T{0} - align));
|
||||||
}
|
}
|
||||||
|
|
||||||
// General purpose aligned division, the result is rounded up not truncated
|
// General purpose aligned division, the result is rounded up not truncated
|
||||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value>>
|
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
|
||||||
constexpr T aligned_div(T value, std::type_identity_t<T> align)
|
constexpr T aligned_div(T value, std::type_identity_t<T> align)
|
||||||
{
|
{
|
||||||
return static_cast<T>(value / align + T{!!(value % align)});
|
return static_cast<T>(value / align + T{!!(value % align)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// General purpose aligned division, the result is rounded to nearest
|
// General purpose aligned division, the result is rounded to nearest
|
||||||
template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
|
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
|
||||||
constexpr T rounded_div(T value, std::type_identity_t<T> align)
|
constexpr T rounded_div(T value, std::type_identity_t<T> align)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_unsigned<T>::value)
|
if constexpr (std::is_unsigned_v<T>)
|
||||||
{
|
{
|
||||||
return static_cast<T>(value / align + T{(value % align) > (align / 2)});
|
return static_cast<T>(value / align + T{(value % align) > (align / 2)});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user