Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing partial specialisation equal operators #927

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading