mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 01:40:36 +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
Notes:
sideshowbarker
2024-07-18 11:37:24 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/c38fafbf4ed Pull-request: https://github.com/SerenityOS/serenity/pull/8142 Issue: https://github.com/SerenityOS/serenity/issues/287 Reviewed-by: https://github.com/awesomekling
1 changed files with 3 additions and 3 deletions
|
@ -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