From 127b9662190deb4895b42eb676b14a011d3cd0ba Mon Sep 17 00:00:00 2001 From: Hendiadyoin1 Date: Wed, 26 Jul 2023 14:53:21 +0200 Subject: [PATCH] AK: Expose Checked::saturating_[add|sub] as static helpers --- AK/Checked.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AK/Checked.h b/AK/Checked.h index 06fd95980f..2ff5c6afa9 100644 --- a/AK/Checked.h +++ b/AK/Checked.h @@ -338,6 +338,22 @@ public: #endif } + template + static constexpr T saturating_add(U a, V b) + { + Checked checked { a }; + checked.saturating_add(b); + return checked.value(); + } + + template + static constexpr T saturating_sub(U a, V b) + { + Checked checked { a }; + checked.saturating_sub(b); + return checked.value(); + } + template [[nodiscard]] static constexpr bool multiplication_would_overflow(U u, V v) {