From c38fafbf4ed622271a6f8f7d5e271324417fed73 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 22 Jun 2021 19:59:20 +0430 Subject: [PATCH] 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. --- AK/StdLibExtras.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 08a5d7a094..1ac5b1347d 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -59,19 +59,19 @@ constexpr SizeType array_size(T (&)[N]) } template -constexpr T min(const T& a, const T& b) +constexpr T min(const T& a, const IdentityType& b) { return b < a ? b : a; } template -constexpr T max(const T& a, const T& b) +constexpr T max(const T& a, const IdentityType& b) { return a < b ? b : a; } template -constexpr T clamp(const T& value, const T& min, const T& max) +constexpr T clamp(const T& value, const IdentityType& min, const IdentityType& max) { VERIFY(max >= min); if (value > max)