On this page
operator==(std::expected)
|
(1) | (since C++23) (T is not cv void) |
|
(2) | (since C++23) (T is cv void) |
|
(3) | (since C++23) (T is not cv void) |
|
(4) | (since C++23) |
Performs comparison operations on expected
objects.
expected
objects. The objects compare equal if and only if lhs.has_value()
and rhs.has_value()
are equal, and the contained values are equal.
- For overload (1), if the expressions
*lhs == *rhs
andlhs.error() == rhs.error()
are not well-formed, or if their results are not convertible tobool
, the program is ill-formed. - For overload (2), if the expressions
lhs.error() == rhs.error()
is not well-formed, or if its result is not convertible tobool
, the program is ill-formed.
expected
object with a value. The objects compare equal if and only if x
contains an expected value, and the contained value is equal to val
.
- If the expression
*x == val
is not well-formed, or if its result is not convertible tobool
, the program is ill-formed.
expected
object with an unexpected value. The objects compare equal if and only if x
contains an unexpected value, and the contained value is equal to e.error()
.
- If the expression
x.error() == e.error()
is not well-formed, or if its result is not convertible tobool
, the program is ill-formed.
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==
.
Parameters
lhs, rhs, x | - | expected object to compare |
val | - | value to compare to the expected value contained in x |
e | - | value to compare to the unexpected value contained in x |
Return value
1) If
lhs.has_value() != rhs.has_value()
, returns false
. Otherwise, if lhs.has_value()
is true, returns *lhs == *rhs
. Otherwise, returns lhs.error() == rhs.error()
.
2) If
lhs.has_value() != rhs.has_value()
, returns false
. Otherwise, if lhs.has_value()
is true, returns true
. Otherwise, returns lhs.error() == rhs.error()
.
3) Returns
x.has_value() && static_cast<bool>(*x == val)
.
4) Returns
!x.has_value() && static_cast<bool>(x.error() == e.error())
.
Exceptions
Throws when and what the comparison throws.
Example
See also
(C++23)
|
represented as an unexpected value (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/utility/expected/operator_cmp