Primary template
template< class T2, class E2 > requires (!std::is_void_v<T2>)
friend constexpr bool operator==( const expected& lhs,
friend constexpr bool operator==( const expected& lhs,
template< class T2 >
friend constexpr bool operator==( const expected& lhs, const T2& val );
void partial specialization
template< class T2, class E2 > requires std::is_void_v<T2>
friend constexpr bool operator==( const expected& lhs,
friend constexpr bool operator==( const expected& lhs,
Performs comparison operations on std::expected objects.
1)Compares two
std::expectedobjects. The objects compare equal if and only if both
lhsand
rhscontain expected values that are equal, or both contain unexpected values that are equal.
If any of the following expressions is ill-formed, or its result is not convertible to bool, the program is ill-formed:
(until C++26)This overload participates in overload resolution only if all following expressions is well-formed, and their results are convertible to bool:
(since C++26)Compares
std::expectedobject with an
std::unexpectedobject. The objects compare equal if and only if
lhscontains an unexpected value that is equal to
unex.error().
If the expression lhs.error() == unex.error() is ill-formed, or its result is not convertible to bool, the program is ill-formed.
(until C++26)This overload participates in overload resolution only if the expression lhs.error() == unex.error() is well-formed, and its result is convertible to bool.
(since C++26) 3)Compares
std::expectedobject with an expected value. The objects compare equal if and only if
lhscontains an expected value that is equal to
val.
If the expression *lhs == val is ill-formed, or its result is not convertible to bool, the program is ill-formed.
(until C++26)This overload participates in overload resolution only if all following conditions are satisfied:
T2
is not a specialization of std::expected.Compares two
std::expectedobjects. The objects compare equal if and only if
lhsand
rhsboth represent expected values, or both contain unexpected values that are equal.
If the expression lhs.error() == rhs.error() is ill-formed, or its result is not convertible to bool, the program is ill-formed.
(until C++26)This overload participates in overload resolution only if the expression lhs.error() == rhs.error() is well-formed, and its result is convertible to bool.
(since C++26) 5)Compares
std::expectedobject with an
std::unexpectedobject. The objects compare equal if and only if
lhscontains an unexpected value that is equal to
unex.error().
If the expression lhs.error() == unex.error() is ill-formed, or its result is not convertible to bool, the program is ill-formed.
(until C++26)This overload participates in overload resolution only if the expression lhs.error() == unex.error() is well-formed, and its result is convertible to bool.
(since C++26)These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::expected<T, E>
is an associated class of the arguments.
The !=
operator is synthesized from operator==
.
lhs.has_value() != rhs.has_value() ? false :
(lhs.has_value() ? *lhs == *rhs : lhs.error() == rhs.error())
2) !lhs.has_value() && static_cast<bool>(lhs.error() == unex.error())
3) lhs.has_value() && static_cast<bool>(*lhs == val) 4)lhs.has_value() != rhs.has_value() ? false :
lhs.has_value() || static_cast<bool>(lhs.error() == rhs.error())
5) !lhs.has_value() && static_cast<bool>(lhs.error() == unex.error())
[edit] ExceptionsThrows when and what the comparison throws.
[edit] Notes [edit] Example#include <expected> #include <iostream> #include <string_view> using namespace std::string_view_literals; int main() { auto x1{"\N{GREEN HEART}"sv}; auto x2{"\N{CROSS MARK}"sv}; std::expected<std::string_view, int> e1{x1}, e2{x1}, e3{x2}; std::unexpected u1{13}; std::cout << "Overload (1):\n" << e1.value() << (e1 == e2 ? " == " : " != ") << *e2 << '\n' << e1.value() << (e1 != e3 ? " != " : " == ") << *e3 << "\n\n"; std::cout << "Overload (2):\n" << e1.value() << (e1 == u1 ? " == " : " != ") << u1.error() << '\n'; e1 = std::unexpected{13}; std::cout << e1.error() << (e1 == u1 ? " == " : " != ") << u1.error() << '\n'; e1 = std::unexpected{31}; std::cout << e1.error() << (e1 != u1 ? " != " : " == ") << u1.error() << '\n'; std::cout << "Overload (3):\n" << *e1 << (e1 == x1 ? " == " : " != ") << x1 << '\n' << *e1 << (e1 != x2 ? " != " : " == ") << x2 << "\n\n"; }
Output:
Overload (1): ð == ð ð != â Overload (2): ð != 13 13 == 13 31 != 13 Overload (3): ð == ð ð != â[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4