mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:27:45 +00:00
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)
This commit is contained in:
parent
cd93fb9656
commit
0e27a6e39e
2 changed files with 109 additions and 6 deletions
21
AK/Checked.h
21
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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue