diff --git a/src/libs/3rdparty/tl_expected/include/tl/expected.hpp b/src/libs/3rdparty/tl_expected/include/tl/expected.hpp index d8ed472bdd1..56101d36331 100644 --- a/src/libs/3rdparty/tl_expected/include/tl/expected.hpp +++ b/src/libs/3rdparty/tl_expected/include/tl/expected.hpp @@ -2278,6 +2278,14 @@ detail::decay_t or_else_impl(Exp &&exp, F &&f) { #endif } // namespace detail +template +constexpr bool operator==(const expected &lhs, + const expected &rhs) { + return (lhs.has_value() != rhs.has_value()) + ? false + : (!lhs.has_value() ? lhs.error() == rhs.error() : true); +} + template constexpr bool operator==(const expected &lhs, const expected &rhs) { @@ -2292,6 +2300,13 @@ constexpr bool operator!=(const expected &lhs, ? 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() : false); +} template constexpr bool operator==(const expected &x, const U &v) { diff --git a/tests/auto/utils/expected/tst_expected.cpp b/tests/auto/utils/expected/tst_expected.cpp index 43e58fb4f90..25240b861a7 100644 --- a/tests/auto/utils/expected/tst_expected.cpp +++ b/tests/auto/utils/expected/tst_expected.cpp @@ -32,6 +32,25 @@ private slots: QVERIFY(!result); } + + void tryCompareVoid() + { + tl::expected e1; + QVERIFY(e1 == e1); + + tl::expected 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)