From b0300545b7adf34171bb24d710240bb58c9f69d8 Mon Sep 17 00:00:00 2001 From: Chiraffollo <5937599+Chiraffollo@users.noreply.github.com> Date: Sat, 20 Jul 2024 10:33:04 +0200 Subject: [PATCH] Fix missing partial specialisation equal operators (#927) --- include/etl/expected.h | 46 +++++++++++++++++++++++++++++++++++++++++- test/test_expected.cpp | 18 +++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/etl/expected.h b/include/etl/expected.h index 143313a71..90a94cb9d 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -976,7 +976,35 @@ bool operator ==(const etl::expected& lhs, const etl::unexpected { return false; } - return lhs.error() == rhs; + return lhs.error() == rhs.error(); +} + +//******************************************* +template +ETL_CONSTEXPR14 +bool operator ==(const etl::expected& lhs, const etl::expected& rhs) +{ + if (lhs.has_value() != rhs.has_value()) + { + return false; + } + if (lhs.has_value()) + { + return true; + } + return lhs.error() == rhs.error(); +} + +//******************************************* +template +ETL_CONSTEXPR14 +bool operator ==(const etl::expected& lhs, const etl::unexpected& rhs) +{ + if (lhs.has_value()) + { + return false; + } + return lhs.error() == rhs.error(); } //******************************************* @@ -1011,6 +1039,22 @@ bool operator !=(const etl::expected& lhs, const etl::unexpected return !(lhs == rhs); } +//******************************************* +template +ETL_CONSTEXPR14 +bool operator !=(const etl::expected& lhs, const etl::expected& rhs) +{ + return !(lhs == rhs); +} + +//******************************************* +template +ETL_CONSTEXPR14 +bool operator !=(const etl::expected& lhs, const etl::unexpected& rhs) +{ + return !(lhs == rhs); +} + //******************************************* template ETL_CONSTEXPR14 diff --git a/test/test_expected.cpp b/test/test_expected.cpp index ce6b78482..cc3aabbd6 100644 --- a/test/test_expected.cpp +++ b/test/test_expected.cpp @@ -665,6 +665,24 @@ namespace } + //************************************************************************* + TEST(test_expected_void_equal_operator) + { + etl::expected test_exp; + etl::expected test_exp2; + etl::expected test_unexp = etl::unexpected(1); + etl::expected test_unexp2 = etl::unexpected(2); + + CHECK_TRUE(test_exp == test_exp2); + CHECK_FALSE(test_exp != test_exp2); + + CHECK_FALSE(test_exp == test_unexp); + CHECK_TRUE(test_exp != test_unexp); + + CHECK_FALSE(test_unexp == test_unexp2); + CHECK_TRUE(test_unexp != test_unexp2); + } + //************************************************************************* TEST(test_unexpected_equal_operator) {