Explorar o código

AK: Expose Checked::saturating_[add|sub] as static helpers

Hendiadyoin1 %!s(int64=2) %!d(string=hai) anos
pai
achega
127b966219
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      AK/Checked.h

+ 16 - 0
AK/Checked.h

@@ -338,6 +338,22 @@ public:
 #endif
     }
 
+    template<typename U, typename V>
+    static constexpr T saturating_add(U a, V b)
+    {
+        Checked checked { a };
+        checked.saturating_add(b);
+        return checked.value();
+    }
+
+    template<typename U, typename V>
+    static constexpr T saturating_sub(U a, V b)
+    {
+        Checked checked { a };
+        checked.saturating_sub(b);
+        return checked.value();
+    }
+
     template<typename U, typename V>
     [[nodiscard]] static constexpr bool multiplication_would_overflow(U u, V v)
     {