mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Expose Checked::saturating_[add|sub] as static helpers
This commit is contained in:
parent
af161a8b83
commit
127b966219
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/127b966219 Pull-request: https://github.com/SerenityOS/serenity/pull/20210 Reviewed-by: https://github.com/kalenikaliaksandr ✅
1 changed files with 16 additions and 0 deletions
16
AK/Checked.h
16
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue