Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add missing equality operators for C++17
  • Loading branch information
X1aomu committed Nov 8, 2024
commit 7c1974a940d0d03a368e07551e7b4504ac836e9b
50 changes: 50 additions & 0 deletions include/zeus/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,12 +2019,14 @@ class expected
return x.error() == y.error();
}
}
#if ZEUS_EXPECTED_CPLUSPLUS < 202'002L
template<class T2, class E2>
[[nodiscard]] friend constexpr std::enable_if_t<!std::is_void_v<T2>, bool> operator!=(const expected &x, const expected<T2, E2> &y) //
noexcept(noexcept(x == y))
{
return !(x == y);
}
#endif

template<class T2>
[[nodiscard]] friend constexpr bool operator==(const expected &x, const T2 &v) //
Expand All @@ -2039,12 +2041,30 @@ class expected
return false;
}
}
#if ZEUS_EXPECTED_CPLUSPLUS < 202'002L
template<class T2>
[[nodiscard]] friend constexpr bool operator!=(const expected &x, const T2 &v) //
noexcept(noexcept(x == v))
{
return !(x == v);
}
template<class T2>
[[nodiscard]] friend constexpr std::enable_if_t<!expected_detail::is_specialization_v<T2, zeus::expected>, bool> operator==(
const T2 &v, const expected &x
) //
noexcept(noexcept(x == v))
{
return x == v;
}
template<class T2>
[[nodiscard]] friend constexpr std::enable_if_t<!expected_detail::is_specialization_v<T2, zeus::expected>, bool> operator!=(
const T2 &v, const expected &x
) //
noexcept(noexcept(x == v))
{
return x != v;
}
#endif

template<class E2>
[[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected<E2> &e) //
Expand All @@ -2059,12 +2079,26 @@ class expected
return static_cast<bool>(x.error() == e.error());
}
}
#if ZEUS_EXPECTED_CPLUSPLUS < 202'002L
template<class E2>
[[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected<E2> &e) //
noexcept(noexcept(x == e))
{
return !(x == e);
}
template<class E2>
[[nodiscard]] friend constexpr bool operator==(const unexpected<E2> &e, const expected &x) //
noexcept(noexcept(x == e))
{
return x == e;
}
template<class E2>
[[nodiscard]] friend constexpr bool operator!=(const unexpected<E2> &e, const expected &x) //
noexcept(noexcept(x == e))
{
return x != e;
}
#endif
};

// standalone swap for non-void value type
Expand Down Expand Up @@ -2702,12 +2736,14 @@ class expected<void, E>
return x.has_value() || static_cast<bool>(x.error() == y.error());
}
}
#if ZEUS_EXPECTED_CPLUSPLUS < 202'002L
template<class T2, class E2>
[[nodiscard]] friend constexpr std::enable_if_t<std::is_void_v<T2>, bool> operator!=(const expected &x, const expected<T2, E2> &y) //
noexcept(noexcept(x == y))
{
return !(x == y);
}
#endif

template<class E2>
[[nodiscard]] friend constexpr bool operator==(const expected &x, const unexpected<E2> &e) //
Expand All @@ -2722,12 +2758,26 @@ class expected<void, E>
return static_cast<bool>(x.error() == e.error());
}
}
#if ZEUS_EXPECTED_CPLUSPLUS < 202'002L
template<class E2>
[[nodiscard]] friend constexpr bool operator!=(const expected &x, const unexpected<E2> &e) //
noexcept(noexcept(x == e))
{
return !(x == e);
}
template<class E2>
[[nodiscard]] friend constexpr bool operator==(const unexpected<E2> &e, const expected &x) //
noexcept(noexcept(x == e))
{
return x == e;
}
template<class E2>
[[nodiscard]] friend constexpr bool operator!=(const unexpected<E2> &e, const expected &x) //
noexcept(noexcept(x == e))
{
return x != e;
}
#endif
};

// standalone swap for void value type
Expand Down