operator==, operator<(std::experimental::optional)
From cppreference.com
< cpp | experimental | optional
Defined in header
<experimental/optional>
|
||
Compare two
optional objects |
||
template< class T >
constexpr bool operator==( const optional<T>& lhs, const optional<T>& rhs ); |
(1) | (library fundamentals TS) |
template< class T >
constexpr bool operator<( const optional<T>& lhs, const optional<T>& rhs ); |
(2) | (library fundamentals TS) |
Compare an
optional object with a nullopt
|
||
template< class T >
constexpr bool operator==( const optional<T>& opt, std::nullopt_t ); |
(3) | (library fundamentals TS) |
template< class T >
constexpr bool operator==( std::nullopt_t, const optional<T>& opt ); |
(4) | (library fundamentals TS) |
template< class T >
constexpr bool operator<( const optional<T>& opt, std::nullopt_t ); |
(5) | (library fundamentals TS) |
template< class T >
constexpr bool operator<( std::nullopt_t, const optional<T>& opt); |
(6) | (library fundamentals TS) |
Compare an
optional object with a T
|
||
template< class T >
constexpr bool operator==( const optional<T>& opt, const T& v ); |
(7) | (library fundamentals TS) |
template< class T >
constexpr bool operator==( const T& value, const optional<T>& opt ); |
(8) | (library fundamentals TS) |
template< class T >
constexpr bool operator<( const optional<T>& opt, const T& v ); |
(9) | (library fundamentals TS) |
Performs comparison operations on optional
objects.
1-2) Compares two
optional
objects, lhs
and rhs
. The contained values are compared only if both lhs
and rhs
contain values. Otherwise, -
-
-
lhs
is considered equal torhs
if, and only if, bothlhs
andrhs
do not contain a value. -
lhs
is considered less thanrhs
if, and only if,rhs
contains a value andlhs
does not.
-
-
3-6) Compares
opt
with a nullopt
. Equivalent to (1-2) when comparing to an optional
that contains a value.
7-9) Compares
opt
with a value
. The values are compared only if opt
contains a value. Otherwise, opt
is considered less than value
.[edit] Parameters
lhs, rhs, opt | - | an optional object to compare
|
value | - | value to compare to the contained value |
Type requirements | ||
-
T must meet the requirements of EqualityComparable in order to use overloads (1, 7-8).
|
[edit] Return value
1) If bool(lhs) != bool(rhs), returns false
Otherwise, if bool(lhs) == bool(rhs) == false, returns true
Otherwise, returns *lhs == *rhs.
2) If bool(rhs) == false returns false
Otherwise, if lhs == false, returns true
Otherwise returns std::less<T>{}(*x, *y)
3) Returns !opt.
4) Returns false.
5) Returns !opt.
6) Returns bool(opt)
7-8) Returns bool(opt) ? *opt == value : false.
9) Returns bool(opt) ? std::less<T>{}(*opt, value) : true.
[edit] Exceptions
1-2) (none)
3-6)
noexcept specification:
noexcept
7-9) (none)