From 9d59f43b9cb6002b22a1f3dbfd70d0d0b3ba67c3 Mon Sep 17 00:00:00 2001 From: Chiraffollo Date: Fri, 19 Jul 2024 21:50:00 +0200 Subject: [PATCH] Fix missing partial specialisation equal operators --- 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) {