diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-24 15:49:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-02-24 15:49:51 +0200 |
commit | 0e5d575feceea4feac4b33e85626719e14f762a1 (patch) | |
tree | cab49f44133cda45be7d030f7116a727e038a2c5 | |
parent | 1c899adcdd4a1a3baa0a554932f0b2b40ae809b8 (diff) |
Add missing optional<> comparison operators
-rw-r--r-- | libbutl/optional.hxx | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/libbutl/optional.hxx b/libbutl/optional.hxx index 28aa95a..f569f8d 100644 --- a/libbutl/optional.hxx +++ b/libbutl/optional.hxx @@ -291,6 +291,8 @@ namespace butl explicit operator bool () const {return this->v_;} }; + // optional ? optional + // template <typename T> inline auto operator== (const optional<T>& x, const optional<T>& y) @@ -320,6 +322,131 @@ namespace butl { return y < x; } + + // optional ? nullopt + // nullopt ? optional + // + template <typename T> + inline auto + operator== (const optional<T>& x, nullopt_t) + { + bool px (x); + return !px; + } + + template <typename T> + inline auto + operator== (nullopt_t, const optional<T>& y) + { + bool py (y); + return !py; + } + + template <typename T> + inline auto + operator!= (const optional<T>& x, nullopt_t y) + { + return !(x == y); + } + + template <typename T> + inline auto + operator!= (nullopt_t x, const optional<T>& y) + { + return !(x == y); + } + + template <typename T> + inline auto + operator< (const optional<T>&, nullopt_t) + { + return false; + } + + template <typename T> + inline auto + operator< (nullopt_t, const optional<T>& y) + { + bool py (y); + return py; + } + + template <typename T> + inline auto + operator> (const optional<T>& x, nullopt_t y) + { + return y < x; + } + + template <typename T> + inline auto + operator> (nullopt_t x, const optional<T>& y) + { + return y < x; + } + + // optional ? T + // T ? optional + // + template <typename T> + inline auto + operator== (const optional<T>& x, const T& y) + { + bool px (x); + return px && *x == y; + } + + template <typename T> + inline auto + operator== (const T& x, const optional<T>& y) + { + bool py (y); + return py && x == *y; + } + + template <typename T> + inline auto + operator!= (const optional<T>& x, const T& y) + { + return !(x == y); + } + + template <typename T> + inline auto + operator!= (const T& x, const optional<T>& y) + { + return !(x == y); + } + + template <typename T> + inline auto + operator< (const optional<T>& x, const T& y) + { + bool px (x); + return !px || *x < y; + } + + template <typename T> + inline auto + operator< (const T& x, const optional<T>& y) + { + bool py (y); + return py && x < *y; + } + + template <typename T> + inline auto + operator> (const optional<T>& x, const T& y) + { + return y < x; + } + + template <typename T> + inline auto + operator> (const T& x, const optional<T>& y) + { + return y < x; + } } namespace std |