forked from qt-creator/qt-creator
Expected: Fix operator==(void, void)
Change-Id: I883f05155f0710fc3a9f92a2e33d4f8722159016 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2278,6 +2278,14 @@ detail::decay_t<Exp> or_else_impl(Exp &&exp, F &&f) {
|
||||
#endif
|
||||
} // namespace detail
|
||||
|
||||
template <class E, class F>
|
||||
constexpr bool operator==(const expected<void, E> &lhs,
|
||||
const expected<void, F> &rhs) {
|
||||
return (lhs.has_value() != rhs.has_value())
|
||||
? false
|
||||
: (!lhs.has_value() ? lhs.error() == rhs.error() : true);
|
||||
}
|
||||
|
||||
template <class T, class E, class U, class F>
|
||||
constexpr bool operator==(const expected<T, E> &lhs,
|
||||
const expected<U, F> &rhs) {
|
||||
@@ -2292,6 +2300,13 @@ constexpr bool operator!=(const expected<T, E> &lhs,
|
||||
? true
|
||||
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
|
||||
}
|
||||
template<class E, class F>
|
||||
constexpr bool operator!=(const expected<void, E> &lhs, const expected<void, F> &rhs)
|
||||
{
|
||||
return (lhs.has_value() != rhs.has_value())
|
||||
? true
|
||||
: (!lhs.has_value() ? lhs.error() != rhs.error() : false);
|
||||
}
|
||||
|
||||
template <class T, class E, class U>
|
||||
constexpr bool operator==(const expected<T, E> &x, const U &v) {
|
||||
|
||||
@@ -32,6 +32,25 @@ private slots:
|
||||
|
||||
QVERIFY(!result);
|
||||
}
|
||||
|
||||
void tryCompareVoid()
|
||||
{
|
||||
tl::expected<void, QString> e1;
|
||||
QVERIFY(e1 == e1);
|
||||
|
||||
tl::expected<void, QString> e2 = make_unexpected("error");
|
||||
QVERIFY(e1 != e2);
|
||||
|
||||
e1 = make_unexpected(QString("error"));
|
||||
QVERIFY(e1 == e2);
|
||||
|
||||
e2 = {};
|
||||
QVERIFY(e1 != e2);
|
||||
|
||||
e1 = {};
|
||||
QVERIFY(e1 == e2);
|
||||
QVERIFY(!(e1 != e2));
|
||||
}
|
||||
};
|
||||
QTEST_GUILESS_MAIN(tst_expected)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user