Skip to content

Commit

Permalink
Fix missing partial specialisation equal operators (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chiraffollo authored and John Wellbelove committed Jul 28, 2024
1 parent 24824d2 commit 0c87973
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
46 changes: 45 additions & 1 deletion include/etl/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,35 @@ bool operator ==(const etl::expected<TValue, TError>& lhs, const etl::unexpected
{
return false;
}
return lhs.error() == rhs;
return lhs.error() == rhs.error();
}

//*******************************************
template <typename TError, typename TError2>
ETL_CONSTEXPR14
bool operator ==(const etl::expected<void, TError>& lhs, const etl::expected<void, TError2>& rhs)
{
if (lhs.has_value() != rhs.has_value())
{
return false;
}
if (lhs.has_value())
{
return true;
}
return lhs.error() == rhs.error();
}

//*******************************************
template <typename TError, typename TError2>
ETL_CONSTEXPR14
bool operator ==(const etl::expected<void, TError>& lhs, const etl::unexpected<TError2>& rhs)
{
if (lhs.has_value())
{
return false;
}
return lhs.error() == rhs.error();
}

//*******************************************
Expand Down Expand Up @@ -1011,6 +1039,22 @@ bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::unexpected
return !(lhs == rhs);
}

//*******************************************
template <typename TError, typename TError2>
ETL_CONSTEXPR14
bool operator !=(const etl::expected<void, TError>& lhs, const etl::expected<void, TError2>& rhs)
{
return !(lhs == rhs);
}

//*******************************************
template <typename TError, typename TError2>
ETL_CONSTEXPR14
bool operator !=(const etl::expected<void, TError>& lhs, const etl::unexpected<TError2>& rhs)
{
return !(lhs == rhs);
}

//*******************************************
template <typename TError, typename TError2>
ETL_CONSTEXPR14
Expand Down
18 changes: 18 additions & 0 deletions test/test_expected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,24 @@ namespace
}


//*************************************************************************
TEST(test_expected_void_equal_operator)
{
etl::expected<void, int> test_exp;
etl::expected<void, int> test_exp2;
etl::expected<void, int> test_unexp = etl::unexpected<int>(1);
etl::expected<void, int> test_unexp2 = etl::unexpected<int>(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)
{
Expand Down

0 comments on commit 0c87973

Please sign in to comment.