diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2020-08-25 23:48:47 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-26 00:55:13 +0200 |
commit | 0e27a6e39eecc21600c62eeee29c6e21d8a92124 (patch) | |
tree | cba2d23ad9e3e97ce2c6e65317f163695d5d93f9 /AK/Checked.h | |
parent | cd93fb96561358525caf66cc39ce77aab91f957a (diff) | |
download | serenity-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.h | 21 |
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> |