mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-04 03:14:29 +02:00
More comparisons
This commit is contained in:
98
expected.hpp
98
expected.hpp
@@ -961,37 +961,79 @@ private:
|
|||||||
// TODO
|
// TODO
|
||||||
template <class E> class expected<void, E> {};
|
template <class E> class expected<void, E> {};
|
||||||
|
|
||||||
template <class T, class E>
|
template <class T, class E, class U, class F>
|
||||||
constexpr bool operator==(const expected<T, E> &lhs,
|
constexpr bool operator==(const expected<T, E> &lhs,
|
||||||
const expected<T, E> &rhs) {
|
const expected<U, F> &rhs) {
|
||||||
return (lhs.has_value() != rhs.has_value())
|
return (lhs.has_value() != rhs.has_value())
|
||||||
? false
|
? false
|
||||||
: (!lhs.has_value() ? lhs.error() == rhs.error() : *lhs == *rhs);
|
: (!lhs.has_value() ? lhs.error() == rhs.error() : *lhs == *rhs);
|
||||||
}
|
}
|
||||||
template <class T, class E>
|
template <class T, class E, class U, class F>
|
||||||
constexpr bool operator!=(const expected<T, E> &lhs,
|
constexpr bool operator!=(const expected<T, E> &lhs,
|
||||||
const expected<T, E> &rhs) {
|
const expected<U, F> &rhs) {
|
||||||
|
return (lhs.has_value() != rhs.has_value())
|
||||||
|
? true
|
||||||
|
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
|
||||||
|
}
|
||||||
|
template <class T, class E, class U, class F>
|
||||||
|
constexpr bool operator<(const expected<T, E> &lhs, const expected<U, F> &rhs) {
|
||||||
return (lhs.has_value() != rhs.has_value())
|
return (lhs.has_value() != rhs.has_value())
|
||||||
? true
|
? true
|
||||||
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
|
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class E>
|
// TODO others
|
||||||
constexpr bool operator==(const expected<T, E> &x, const T &v) {
|
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator==(const expected<T, E> &x, const U &v) {
|
||||||
return x.has_value() ? *x == v : false;
|
return x.has_value() ? *x == v : false;
|
||||||
}
|
}
|
||||||
template <class T, class E>
|
template <class T, class E, class U>
|
||||||
constexpr bool operator==(const T &v, const expected<T, E> &x) {
|
constexpr bool operator==(const U &v, const expected<T, E> &x) {
|
||||||
return x.has_value() ? *x == v : false;
|
return x.has_value() ? *x == v : false;
|
||||||
}
|
}
|
||||||
template <class T, class E>
|
template <class T, class E, class U>
|
||||||
constexpr bool operator!=(const expected<T, E> &x, const T &v) {
|
constexpr bool operator!=(const expected<T, E> &x, const U &v) {
|
||||||
return x.has_value() ? *x != v : true;
|
return x.has_value() ? *x != v : true;
|
||||||
}
|
}
|
||||||
template <class T, class E>
|
template <class T, class E, class U>
|
||||||
constexpr bool operator!=(const T &v, const expected<T, E> &x) {
|
constexpr bool operator!=(const U &v, const expected<T, E> &x) {
|
||||||
return x.has_value() ? *x != v : true;
|
return x.has_value() ? *x != v : true;
|
||||||
}
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator<(const expected<T, E> &x, const U &v) {
|
||||||
|
return x.has_value() ? *x < v : true;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator<(const U &v, const expected<T, E> &x) {
|
||||||
|
return x.has_value() ? v < *x : false;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator<=(const expected<T, E> &x, const U &v) {
|
||||||
|
return x.has_value() ? *x <= v : true;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator<=(const U &v, const expected<T, E> &x) {
|
||||||
|
return x.has_value() ? v <= *x : false;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator>(const expected<T, E> &x, const U &v) {
|
||||||
|
return x.has_value() ? *x > v : false;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator>(const U &v, const expected<T, E> &x) {
|
||||||
|
return x.has_value() ? v > *x : true;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator>=(const expected<T, E> &x, const U &v) {
|
||||||
|
return x.has_value() ? *x >= v : false;
|
||||||
|
}
|
||||||
|
template <class T, class E, class U>
|
||||||
|
constexpr bool operator>=(const U &v, const expected<T, E> &x) {
|
||||||
|
return x.has_value() ? v >= *x : true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO others
|
||||||
|
|
||||||
template <class T, class E>
|
template <class T, class E>
|
||||||
constexpr bool operator==(const expected<T, E> &x, const unexpected<E> &e) {
|
constexpr bool operator==(const expected<T, E> &x, const unexpected<E> &e) {
|
||||||
@@ -1009,6 +1051,38 @@ template <class T, class E>
|
|||||||
constexpr bool operator!=(const unexpected<E> &e, const expected<T, E> &x) {
|
constexpr bool operator!=(const unexpected<E> &e, const expected<T, E> &x) {
|
||||||
return x.has_value() ? false : x.error() != e.value();
|
return x.has_value() ? false : x.error() != e.value();
|
||||||
}
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator<(const expected<T, E> &x, const unexpected<E> &e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator<(const unexpected<E> &e, const expected<T, E> &x) {
|
||||||
|
return x.has_value();
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator<=(const expected<T, E> &x, const unexpected<E> &e) {
|
||||||
|
return !x.has_value();
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator<=(const unexpected<E> &e, const expected<T, E> &x) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator>(const expected<T, E> &x, const unexpected<E> &e) {
|
||||||
|
return x.has_value();
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator>(const unexpected<E> &e, const expected<T, E> &x) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator>=(const expected<T, E> &x, const unexpected<E> &e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
template <class T, class E>
|
||||||
|
constexpr bool operator>=(const unexpected<E> &e, const expected<T, E> &x) {
|
||||||
|
return !x.has_value();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO is_swappable
|
// TODO is_swappable
|
||||||
template <class T, class E,
|
template <class T, class E,
|
||||||
|
Reference in New Issue
Block a user