Defined in header <optional> | ||
---|---|---|
Compare two optional objects | ||
template< class T, class U > constexpr bool operator==( const optional<T>& lhs, const optional<U>& rhs ); | (1) | (since C++17) |
template< class T, class U > constexpr bool operator!=( const optional<T>& lhs, const optional<U>& rhs ); | (2) | (since C++17) |
template< class T, class U > constexpr bool operator<( const optional<T>& lhs, const optional<U>& rhs ); | (3) | (since C++17) |
template< class T, class U > constexpr bool operator<=( const optional<T>& lhs, const optional<U>& rhs ); | (4) | (since C++17) |
template< class T, class U > constexpr bool operator>( const optional<T>& lhs, const optional<U>& rhs ); | (5) | (since C++17) |
template< class T, class U > constexpr bool operator>=( const optional<T>& lhs, const optional<U>& 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, class U > constexpr bool operator==( const optional<T>& opt, const U& value); | (19) | (since C++17) |
template< class T, class U > constexpr bool operator==( const U& value, const optional<T>& opt ); | (20) | (since C++17) |
template< class T, class U > constexpr bool operator!=( const optional<T>& opt, const U& value ); | (21) | (since C++17) |
template< class T, class U > constexpr bool operator!=( const U& value, const optional<T>& opt ); | (22) | (since C++17) |
template< class T, class U > constexpr bool operator<( const optional<T>& opt, const U& value ); | (23) | (since C++17) |
template< class T, class U > constexpr bool operator<( const U& value, const optional<T>& opt ); | (24) | (since C++17) |
template< class T, class U > constexpr bool operator<=( const optional<T>& opt, const U& value ); | (25) | (since C++17) |
template< class T, class U > constexpr bool operator<=( const U& value, const optional<T>& opt); | (26) | (since C++17) |
template< class T, class U > constexpr bool operator>( const optional<T>& opt, const U& value ); | (27) | (since C++17) |
template< class T, class U > constexpr bool operator>( const U& value, const optional<T>& opt ); | (28) | (since C++17) |
template< class T, class U > constexpr bool operator>=( const optional<T>& opt, const U& value ); | (29) | (since C++17) |
template< class T, class U > constexpr bool operator>=( const U& value, const optional<T>& opt ); | (30) | (since C++17) |
Performs comparison operations on optional
objects.
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 to rhs
if, and only if, both lhs
and rhs
do not contain a value. lhs
is considered less than rhs
if, and only if, rhs
contains a value and lhs
does not. opt
with a nullopt
. Equivalent to (1-6) when comparing to an optional
that does not contain a value.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
. If the corresponding comparison expression between *opt
and value
is not well-formed, or if its result is not convertible to bool
, the behavior is undefined.lhs, rhs, opt | - | an optional object to compare |
value | - | value to compare to the contained value |
bool(lhs) != bool(rhs)
, returns false
Otherwise, if bool(lhs) == false
(and so bool(rhs) == false
as well), returns true
Otherwise, returns *lhs == *rhs
.
bool(lhs) != bool(rhs)
, returns true
Otherwise, if bool(lhs) == false
(and so bool(rhs) == false
as well), returns false
Otherwise, returns *lhs != *rhs
.
bool(rhs) == false
returns false
Otherwise, if bool(lhs) == false
, returns true
Otherwise returns *lhs < *rhs
.
bool(lhs) == false
returns true
Otherwise, if bool(rhs) == false
, returns false
Otherwise returns *lhs <= *rhs
.
bool(lhs) == false
returns false
Otherwise, if bool(rhs) == false
, returns true
Otherwise returns *lhs > *rhs
.
bool(rhs) == false
returns true
Otherwise, if bool(lhs) == false
, returns false
Otherwise returns *lhs >= *rhs
.
!opt
.bool(opt)
.false
.bool(opt)
.!opt
.true
.bool(opt)
.false
.true
.!opt
.bool(opt) ? *opt == value : false
.bool(opt) ? value == *opt : false
.bool(opt) ? *opt != value : true
.bool(opt) ? value != *opt : true
.bool(opt) ? *opt < value : true
.bool(opt) ? value < *opt : false
.bool(opt) ? *opt <= value : true
.bool(opt) ? value <= *opt : false
.bool(opt) ? *opt > value : false
.bool(opt) ? value > *opt : true
.bool(opt) ? *opt >= value : false
.bool(opt) ? value >= *opt : true
.noexcept
specification: noexcept
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/optional/operator_cmp