operator==, !=, <, <=, >, >=(std::experimental::optional)
来自 cppreference.cn
< 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) (无)