mirror of
https://github.com/TartanLlama/expected.git
synced 2025-08-02 18:34:29 +02:00
Fix equality test for expected<void,E>
This commit is contained in:
@@ -2276,6 +2276,20 @@ constexpr bool operator!=(const expected<T, E> &lhs,
|
|||||||
? true
|
? true
|
||||||
: (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs);
|
: (!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())
|
||||||
|
? false
|
||||||
|
: (!lhs.has_value() ? lhs.error() == rhs.error() : true);
|
||||||
|
}
|
||||||
|
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>
|
template <class T, class E, class U>
|
||||||
constexpr bool operator==(const expected<T, E> &x, const U &v) {
|
constexpr bool operator==(const expected<T, E> &x, const U &v) {
|
||||||
|
@@ -2,5 +2,16 @@
|
|||||||
#include <tl/expected.hpp>
|
#include <tl/expected.hpp>
|
||||||
|
|
||||||
TEST_CASE("Relational operators", "[relops]") {
|
TEST_CASE("Relational operators", "[relops]") {
|
||||||
//TODO
|
tl::expected<int, int> o1 = 42;
|
||||||
|
tl::expected<int, int> o2{tl::unexpect, 0};
|
||||||
|
const tl::expected<int, int> o3 = 42;
|
||||||
|
|
||||||
|
REQUIRE(o1 == o1);
|
||||||
|
REQUIRE(o1 != o2);
|
||||||
|
REQUIRE(o1 == o3);
|
||||||
|
REQUIRE(o3 == o3);
|
||||||
|
|
||||||
|
tl::expected<void, int> o6;
|
||||||
|
|
||||||
|
REQUIRE(o6 == o6);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user