summaryrefslogtreecommitdiff
path: root/AK/Checked.h
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2020-08-25 23:48:47 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-26 00:55:13 +0200
commit0e27a6e39eecc21600c62eeee29c6e21d8a92124 (patch)
treecba2d23ad9e3e97ce2c6e65317f163695d5d93f9 /AK/Checked.h
parentcd93fb96561358525caf66cc39ce77aab91f957a (diff)
downloadserenity-0e27a6e39eecc21600c62eeee29c6e21d8a92124.zip
AK: Demonstrate and fix Checked
Specifically: - post-increment actually implemented pre-increment - helper-templates that provided operator{+,-,*,/}() couldn't possibly work, because the interface of add (etc) were incompatible (not taking a Checked<>, and returning void)
Diffstat (limited to 'AK/Checked.h')
-rw-r--r--AK/Checked.h21
1 files changed, 15 insertions, 6 deletions
diff --git a/AK/Checked.h b/AK/Checked.h
index d0877082b4..068908ade2 100644
--- a/AK/Checked.h
+++ b/AK/Checked.h
@@ -228,10 +228,11 @@ public:
return *this;
}
- Checked& operator++(int)
+ Checked operator++(int)
{
+ Checked old { *this };
add(1);
- return *this;
+ return old;
}
template<typename U, typename V>
@@ -278,25 +279,33 @@ private:
template<typename T>
inline Checked<T> operator+(const Checked<T>& a, const Checked<T>& b)
{
- return Checked<T>(a).add(b);
+ Checked<T> c { a };
+ c.add(b.value());
+ return c;
}
template<typename T>
inline Checked<T> operator-(const Checked<T>& a, const Checked<T>& b)
{
- return Checked<T>(a).sub(b);
+ Checked<T> c { a };
+ c.sub(b.value());
+ return c;
}
template<typename T>
inline Checked<T> operator*(const Checked<T>& a, const Checked<T>& b)
{
- return Checked<T>(a).mul(b);
+ Checked<T> c { a };
+ c.mul(b.value());
+ return c;
}
template<typename T>
inline Checked<T> operator/(const Checked<T>& a, const Checked<T>& b)
{
- return Checked<T>(a).div(b);
+ Checked<T> c { a };
+ c.div(b.value());
+ return c;
}
template<typename T>