Skip to content

Commit

Permalink
Fix operator==() for void 'value' type (#51, thanks @Crzyrndm)
Browse files Browse the repository at this point in the history
Change operator==() for non-void expected<> to align with above.
  • Loading branch information
martinmoene committed Nov 13, 2022
1 parent 70db1b5 commit c32b0e7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions include/nonstd/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2172,19 +2172,23 @@ template< typename T1, typename E1, typename T2, typename E2
>
constexpr bool operator==( expected<T1,E1> const & x, expected<T2,E2> const & y )
{
return bool(x) != bool(y) ? false : bool(x) == false ? x.error() == y.error() : *x == *y;
return bool(x) != bool(y) ? false : bool(x) ? *x == *y : x.error() == y.error();
}

template< typename T1, typename E1, typename T2, typename E2 >
constexpr bool operator!=( expected<T1,E1> const & x, expected<T2,E2> const & y )
template< typename T1, typename E1, typename T2, typename E2
nsel_REQUIRES_T(
std::is_void<T1>::value && std::is_void<T2>::value
)
>
constexpr bool operator==( expected<T1,E1> const & x, expected<T2,E2> const & y )
{
return !(x == y);
return bool(x) != bool(y) ? false : bool(x) || static_cast<bool>( x.error() == y.error() );
}

template< typename E1, typename E2 >
constexpr bool operator==( expected<void,E1> const & x, expected<void,E2> const & y )
template< typename T1, typename E1, typename T2, typename E2 >
constexpr bool operator!=( expected<T1,E1> const & x, expected<T2,E2> const & y )
{
return bool(x) != bool(y) ? false : bool(x) == false ? x.error() == y.error() : true;
return !(x == y);
}

#if nsel_P0323R <= 2
Expand Down

0 comments on commit c32b0e7

Please sign in to comment.