AK: Make {min,max,clamp}(T, U) work when U can be implicitly cast to T

It was really annoying to `static_cast` the arguments to be the same
type, so instead of doing that, just convert the second one to the first
one, and let the compiler warn about sign differences and truncation.
This commit is contained in:
Ali Mohammad Pur 2021-06-22 19:59:20 +04:30 committed by Andreas Kling
parent 3b2a528b33
commit c38fafbf4e
Notes: sideshowbarker 2024-07-18 11:37:24 +09:00

View file

@ -59,19 +59,19 @@ constexpr SizeType array_size(T (&)[N])
}
template<typename T>
constexpr T min(const T& a, const T& b)
constexpr T min(const T& a, const IdentityType<T>& b)
{
return b < a ? b : a;
}
template<typename T>
constexpr T max(const T& a, const T& b)
constexpr T max(const T& a, const IdentityType<T>& b)
{
return a < b ? b : a;
}
template<typename T>
constexpr T clamp(const T& value, const T& min, const T& max)
constexpr T clamp(const T& value, const IdentityType<T>& min, const IdentityType<T>& max)
{
VERIFY(max >= min);
if (value > max)