mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-02 22:24:26 +00:00
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:
parent
3b2a528b33
commit
c38fafbf4e
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue