Namespaces
Variants

operator==, !=, <, <=, >, >= (std::experimental::optional)

From cppreference.net
定义于头文件 <experimental/optional>
比较两个 optional 对象
template < class T >
constexpr bool operator == ( const optional < T > & lhs, const optional < T > & rhs ) ;
(1) (库基础 TS)
template < class T >
constexpr bool operator ! = ( const optional < T > & lhs, const optional < T > & rhs ) ;
(2) (库基础 TS)
template < class T >
constexpr bool operator < ( const optional < T > & lhs, const optional < T > & rhs ) ;
(3) (库基础 TS)
template < class T >
constexpr bool operator <= ( const optional < T > & lhs, const optional < T > & rhs ) ;
(4) (库基础 TS)
template < class T >
constexpr bool operator > ( const optional < T > & lhs, const optional < T > & rhs ) ;
(5) (库基础 TS)
template < class T >
constexpr bool operator >= ( const optional < T > & lhs, const optional < T > & rhs ) ;
(6) (库基础 TS)
比较 optional 对象与 nullopt
template < class T >
constexpr bool operator == ( const optional < T > & opt, std:: nullopt_t ) noexcept ;
(7) (库基础 TS)
template < class T >
constexpr bool operator == ( std:: nullopt_t , const optional < T > & opt ) noexcept ;
(8) (库基础 TS)
template < class T >
constexpr bool operator ! = ( const optional < T > & opt, std:: nullopt_t ) noexcept ;
(9) (库基础 TS)
template < class T >
constexpr bool operator ! = ( std:: nullopt_t , const optional < T > & opt ) noexcept ;
(10) (库基础 TS)
template < class T >
constexpr bool operator < ( const optional < T > & opt, std:: nullopt_t ) noexcept ;
(11) (库基础 TS)
template < class T >
constexpr bool operator < ( std:: nullopt_t , const optional < T > & opt ) noexcept ;
(12) (库基础 TS)
template < class T >
constexpr bool operator <= ( const optional < T > & opt, std:: nullopt_t ) noexcept ;
(13) (库基础 TS)
template < class T >
constexpr bool operator <= ( std:: nullopt_t , const optional < T > & opt ) noexcept</span

optional 对象执行比较操作。

1-6) 比较两个 optional 对象 lhs rhs 。仅当 lhs rhs 均包含值时,才会对所含值进行比较( (1,2) 使用 operator == (3-6) 使用 operator < )。否则,
  • 当且仅当 lhs rhs 均不包含值时,二者被视为 相等
  • 当且仅当 rhs 包含值而 lhs 不包含值时, lhs 被视为 小于 rhs
7-18) opt nullopt 进行比较。当与不包含值的 optional 进行比较时,等同于 (1-6) 的情况。
19-30) opt value 进行比较。仅当 opt 包含值时才会进行值比较( (19-22) 使用 operator == (23-30) 使用 operator < )。否则, opt 被视为 小于 value

参数

lhs, rhs, opt - 待比较的 optional 对象
value - 与所含值进行比较的值
类型要求
-
T 必须满足 EqualityComparable 要求才能使用重载 (1,2)。

返回值

1) 如果 bool ( lhs ) ! = bool ( rhs ) ,返回 false
否则,如果 bool ( lhs ) == false (那么 bool ( rhs ) == false 也成立),则返回 true
否则,返回 * lhs == * rhs
2) 返回 ! ( lhs == rhs )
3) bool ( rhs ) == false 返回 false
否则,若 bool ( lhs ) == false ,则返回 true
否则返回 * x < * y
4) 返回 ! ( rhs < lhs )
5) 返回 rhs < lhs
6) 返回 ! ( lhs < rhs )
7,8) 返回 ! opt
9,10) 返回 bool ( opt )
11) 返回 false
12) 返回 bool ( opt )
13) 返回 ! opt
14) 返回 true
15) 返回 bool ( opt )
16) 返回 false
17) 返回 true
18) 返回 ! opt
19) 返回 bool ( opt ) ? * opt == value : false
20) 返回 bool ( opt ) ? value == * opt : false
21) 返回 bool ( opt ) ? ! ( * opt == value ) : true
22) 返回 bool ( opt ) ? ! ( value == * opt ) : true
23) 返回 bool ( opt ) ? * opt < value : true
24) 返回 bool ( opt ) ? value < * opt : false
25) 返回 ! ( opt > value )
26) 返回 ! ( value > opt )
27) 返回 bool ( opt ) ? value < * opt : false
28) 返回 bool ( opt ) ? * opt < value : true
29) 返回 ! ( opt < value )
30) 返回 ! ( value < opt )

异常

1-6) (无)
19-30) (无)