operator==, !=, <, <=, >, >=(std::optional)
From cppreference.com
Defined in header
<optional>
|
||
Compare two
optional objects |
||
template< class T >
constexpr bool operator==( const optional<T>& lhs, const optional<T>& rhs ); |
(1) | (since C++17) |
template< class T >
constexpr bool operator!=( const optional<T>& lhs, const optional<T>& rhs ); |
(2) | (since C++17) |
template< class T >
constexpr bool operator<( const optional<T>& lhs, const optional<T>& rhs ); |
(3) | (since C++17) |
template< class T >
constexpr bool operator<=( const optional<T>& lhs, const optional<T>& rhs ); |
(4) | (since C++17) |
template< class T >
constexpr bool operator>( const optional<T>& lhs, const optional<T>& rhs ); |
(5) | (since C++17) |
template< class T >
constexpr bool operator>=( const optional<T>& lhs, const optional<T>& rhs ); |
(6) | (since C++17) |
Compare an
optional object with a nullopt
|
||
template< class T >
constexpr bool operator==( const optional<T>& opt, std::nullopt_t ); |
(7) | (since C++17) |
template< class T >
constexpr bool operator==( std::nullopt_t, const optional<T>& opt ); |
(8) | (since C++17) |
template< class T >
constexpr bool operator!=( const optional<T>& opt, std::nullopt_t ); |
(9) | (since C++17) |
template< class T >
constexpr bool operator!=( std::nullopt_t, const optional<T>& opt ); |
(10) | (since C++17) |
template< class T >
constexpr bool operator<( const optional<T>& opt, std::nullopt_t ); |
(11) | (since C++17) |
template< class T >
constexpr bool operator<( std::nullopt_t, const optional<T>& opt ); |
(12) | (since C++17) |
template< class T >
constexpr bool operator<=( const optional<T>& opt, std::nullopt_t ); |
(13) | (since C++17) |
template< class T >
constexpr bool operator<=( std::nullopt_t, const optional<T>& opt); |
(14) | (since C++17) |
template< class T >
constexpr bool operator>( const optional<T>& opt, std::nullopt_t ); |
(15) | (since C++17) |
template< class T >
constexpr bool operator>( std::nullopt_t, const optional<T>& opt ); |
(16) | (since C++17) |
template< class T >
constexpr bool operator>=( const optional<T>& opt, std::nullopt_t ); |
(17) | (since C++17) |
template< class T >
constexpr bool operator>=( std::nullopt_t, const optional<T>& opt ); |
(18) | (since C++17) |
Compare an
optional object with a T
|
||
template< class T >
constexpr bool operator==( const optional<T>& opt, const T& value); |
(19) | (since C++17) |
template< class T >
constexpr bool operator==( const T& value, const optional<T>& opt ); |
(20) | (since C++17) |
template< class T >
constexpr bool operator!=( const optional<T>& opt, const T& value ); |
(21) | (since C++17) |
template< class T >
constexpr bool operator!=( const T& value, const optional<T>& opt ); |
(22) | (since C++17) |
template< class T >
constexpr bool operator<( const optional<T>& opt, const T& value ); |
(23) | (since C++17) |
template< class T >
constexpr bool operator<( const T& value, const optional<T>& opt ); |
(24) | (since C++17) |
template< class T >
constexpr bool operator<=( const optional<T>& opt, const T& value ); |
(25) | (since C++17) |
template< class T >
constexpr bool operator<=( const T& value, const optional<T>& opt); |
(26) | (since C++17) |
template< class T >
constexpr bool operator>( const optional<T>& opt, const T& value ); |
(27) | (since C++17) |
template< class T >
constexpr bool operator>( const T& value, const optional<T>& opt ); |
(28) | (since C++17) |
template< class T >
constexpr bool operator>=( const optional<T>& opt, const T& value ); |
(29) | (since C++17) |
template< class T >
constexpr bool operator>=( const T& value, const optional<T>& opt ); |
(30) | (since C++17) |
Performs comparison operations on optional
objects.
1-6) Compares two
optional
objects, lhs
and rhs
. The contained values are compared (using the corresponding operator of T
) 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.
-
-
7-18) Compares
opt
with a nullopt
. Equivalent to (1-6) when comparing to an optional
that does not contain a value.
19-30) Compares
opt
with a value
. The values are compared (using the corresponding operator of T
) 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 |
[edit] Return value
1) If bool(lhs) != bool(rhs), returns false
Otherwise, if bool(lhs) == false (and so bool(rhs) == false as well), returns true
2) If bool(lhs) != bool(rhs), returns true
Otherwise, if bool(lhs) == false (and so bool(rhs) == false as well), returns false
3) If bool(rhs) == false returns false
Otherwise, if bool(lhs) == false, returns true
4) If bool(lhs) == false returns true
Otherwise, if bool(rhs) == false, returns false
5) If bool(lhs) == false returns false
Otherwise, if bool(rhs) == false, returns true
6) If bool(rhs) == false returns true
Otherwise, if bool(lhs) == false, returns false
7-8) Returns !opt.
9-10) Returns bool(opt).
11) Returns false.
12) Returns bool(opt).
13) Returns !opt.
14) Returns true.
15) Returns bool(opt).
16) Returns false.
17) Returns true.
18) Returns !opt.
19) Returns bool(opt) ? *opt == value : false.
20) Returns bool(opt) ? value == *opt : false.
21) Returns bool(opt) ? *opt != value : true.
22) Returns bool(opt) ? value != *opt : true.
23) Returns bool(opt) ? *opt < value : true.
24) Returns bool(opt) ? value < *opt : false.
25) Returns bool(opt) ? *opt <= value : true.
26) Returns bool(opt) ? value <= *opt : false.
27) Returns bool(opt) ? *opt > value : false.
28) Returns bool(opt) ? value > *opt : true.
29) Returns bool(opt) ? *opt >= value : false.
30) Returns bool(opt) ? value >= *opt : true.
[edit] Exceptions
1-6) (none)
7-18)
noexcept specification:
noexcept
19-30) (none)