diff --git a/AK/Checked.h b/AK/Checked.h index 9be8affdcb..efa6640344 100644 --- a/AK/Checked.h +++ b/AK/Checked.h @@ -1,6 +1,6 @@ /* * Copyright (C) 2011-2019 Apple Inc. All rights reserved. - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -186,24 +186,52 @@ public: m_value /= other; } + constexpr Checked& operator+=(const Checked& other) + { + m_overflow |= other.m_overflow; + add(other.value()); + return *this; + } + constexpr Checked& operator+=(T other) { add(other); return *this; } + constexpr Checked& operator-=(const Checked& other) + { + m_overflow |= other.m_overflow; + sub(other.value()); + return *this; + } + constexpr Checked& operator-=(T other) { sub(other); return *this; } + constexpr Checked& operator*=(const Checked& other) + { + m_overflow |= other.m_overflow; + mul(other.value()); + return *this; + } + constexpr Checked& operator*=(T other) { mul(other); return *this; } + constexpr Checked& operator/=(const Checked& other) + { + m_overflow |= other.m_overflow; + div(other.value()); + return *this; + } + constexpr Checked& operator/=(T other) { div(other);