diff --git a/expected.hpp b/expected.hpp index f672b68..8252372 100644 --- a/expected.hpp +++ b/expected.hpp @@ -544,7 +544,7 @@ public: : result(unexpect, std::move(this->error())); } #endif -#endif +#endif #ifdef TL_EXPECTED_CXX14 /// \brief Carries out some operation on the stored object if there is one. @@ -961,37 +961,79 @@ private: // TODO template class expected {}; -template +template constexpr bool operator==(const expected &lhs, - const expected &rhs) { + const expected &rhs) { return (lhs.has_value() != rhs.has_value()) ? false : (!lhs.has_value() ? lhs.error() == rhs.error() : *lhs == *rhs); } -template +template constexpr bool operator!=(const expected &lhs, - const expected &rhs) { + const expected &rhs) { + return (lhs.has_value() != rhs.has_value()) + ? true + : (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs); +} + template +constexpr bool operator<(const expected &lhs, const expected &rhs) { return (lhs.has_value() != rhs.has_value()) ? true : (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs); } -template -constexpr bool operator==(const expected &x, const T &v) { +// TODO others + +template +constexpr bool operator==(const expected &x, const U &v) { return x.has_value() ? *x == v : false; } -template -constexpr bool operator==(const T &v, const expected &x) { +template +constexpr bool operator==(const U &v, const expected &x) { return x.has_value() ? *x == v : false; } -template -constexpr bool operator!=(const expected &x, const T &v) { +template +constexpr bool operator!=(const expected &x, const U &v) { return x.has_value() ? *x != v : true; } -template -constexpr bool operator!=(const T &v, const expected &x) { +template +constexpr bool operator!=(const U &v, const expected &x) { return x.has_value() ? *x != v : true; } +template +constexpr bool operator<(const expected &x, const U &v) { + return x.has_value() ? *x < v : true; +} +template +constexpr bool operator<(const U &v, const expected &x) { + return x.has_value() ? v < *x : false; +} +template +constexpr bool operator<=(const expected &x, const U &v) { + return x.has_value() ? *x <= v : true; +} +template +constexpr bool operator<=(const U &v, const expected &x) { + return x.has_value() ? v <= *x : false; +} +template +constexpr bool operator>(const expected &x, const U &v) { + return x.has_value() ? *x > v : false; +} +template +constexpr bool operator>(const U &v, const expected &x) { + return x.has_value() ? v > *x : true; +} +template +constexpr bool operator>=(const expected &x, const U &v) { + return x.has_value() ? *x >= v : false; +} +template +constexpr bool operator>=(const U &v, const expected &x) { + return x.has_value() ? v >= *x : true; +} + +// TODO others template constexpr bool operator==(const expected &x, const unexpected &e) { @@ -1009,6 +1051,38 @@ template constexpr bool operator!=(const unexpected &e, const expected &x) { return x.has_value() ? false : x.error() != e.value(); } +template +constexpr bool operator<(const expected &x, const unexpected &e) { + return false; +} +template +constexpr bool operator<(const unexpected &e, const expected &x) { + return x.has_value(); +} +template +constexpr bool operator<=(const expected &x, const unexpected &e) { + return !x.has_value(); +} +template +constexpr bool operator<=(const unexpected &e, const expected &x) { + return true; +} +template +constexpr bool operator>(const expected &x, const unexpected &e) { + return x.has_value(); +} +template +constexpr bool operator>(const unexpected &e, const expected &x) { + return false; +} +template +constexpr bool operator>=(const expected &x, const unexpected &e) { + return true; +} +template +constexpr bool operator>=(const unexpected &e, const expected &x) { + return !x.has_value(); +} // TODO is_swappable template