operator==, !=, <, <=, >, >=(std::experimental::optional)
來自 cppreference.com
< cpp | experimental | optional
定義於標頭檔案 <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; |
(14) | (庫基礎 TS) |
template< class T > constexpr bool operator>( const optional<T>& opt, std::nullopt_t ) noexcept; |
(15) | (庫基礎 TS) |
template< class T > constexpr bool operator>( std::nullopt_t, const optional<T>& opt ) noexcept; |
(16) | (庫基礎 TS) |
template< class T > constexpr bool operator>=( const optional<T>& opt, std::nullopt_t ) noexcept; |
(17) | (庫基礎 TS) |
template< class T > constexpr bool operator>=( std::nullopt_t, const optional<T>& opt ) noexcept; |
(18) | (庫基礎 TS) |
將 optional 物件與 T 進行比較 |
||
template< class T > constexpr bool operator==( const optional<T>& opt, const T& value ); |
(19) | (庫基礎 TS) |
template< class T > constexpr bool operator==( const T& value, const optional<T>& opt ); |
(20) | (庫基礎 TS) |
template< class T > constexpr bool operator!=( const optional<T>& opt, const T& value ); |
(21) | (庫基礎 TS) |
template< class T > constexpr bool operator!=( const T& value, const optional<T>& opt ); |
(22) | (庫基礎 TS) |
template< class T > constexpr bool operator<( const optional<T>& opt, const T& value ); |
(23) | (庫基礎 TS) |
template< class T > constexpr bool operator<( const T& value, const optional<T>& opt ); |
(24) | (庫基礎 TS) |
template< class T > constexpr bool operator<=( const optional<T>& opt, const T& value ); |
(25) | (庫基礎 TS) |
template< class T > constexpr bool operator<=( const T& value, const optional<T>& opt ); |
(26) | (庫基礎 TS) |
template< class T > constexpr bool operator>( const optional<T>& opt, const T& value ); |
(27) | (庫基礎 TS) |
template< class T > constexpr bool operator>( const T& value, const optional<T>& opt ); |
(28) | (庫基礎 TS) |
template< class T > constexpr bool operator>=( const optional<T>& opt, const T& value ); |
(29) | (庫基礎 TS) |
template< class T > constexpr bool operator>=( const T& value, const optional<T>& opt ); |
(30) | (庫基礎 TS) |
對 optional
物件執行比較操作。
1-6) 比較兩個
optional
物件,lhs 和 rhs。僅當 lhs 和 rhs 都包含值時,才比較它們包含的值(對於 (1,2) 使用 operator==,對於 (3-6) 使用 operator<)。否則:- lhs 被視為 等於 rhs,當且僅當 lhs 和 rhs 都不包含值。
- lhs 被視為 小於 rhs,當且僅當 rhs 包含值而 lhs 不包含。
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 | - | 要與包含值比較的值 |
型別要求 | ||
-為了使用過載 (1,2),T 必須滿足 EqualityComparable 的要求。 |
[編輯] 返回值
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) (無)