operators (std::optional)
运算符=,%21=,<,<=,>=%28std::可选的%29
Defined in header | | |
---|---|---|
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) |
对optional
物品。
1-6%29比较两optional
物体,lhs
和rhs
使用相应的运算符将所包含的值%28进行比较。T
%29只有当两者兼而有之时lhs
和rhs
包含值。否则,
lhs
被认为等于
rhs
当且仅当lhs
和rhs
不包含值。
lhs
被认为少于
rhs
如果,而且只有在这样的情况下,rhs
包含一个值和lhs
不会的。
7-18%29比较opt
带着nullopt
值等于%281-6%29。optional
它不包含值。
19-30%29比较opt
带着value
。使用相应的运算符将值%28进行比较。T
%29只在以下情况下opt
包含一个值。否则,opt
被认为少于
value
。如果对应的比较表达式*opt
和value
格式不正确,或者如果其结果不能转换为bool
,该行为是未定义的。
参数
lhs, rhs, opt | - | an optional object to compare |
---|---|---|
value | - | value to compare to the contained value |
返回值
1%29bool(lhs) != bool(rhs)
、回报false
否则,如果bool(lhs) == false
%28左右bool(rhs) == false
以及%29,返回true
否则,返回*lhs == *rhs
...
2%29bool(lhs) != bool(rhs)
、回报true
否则,如果bool(lhs) == false
%28左右bool(rhs) == false
以及%29,返回false
否则,返回*lhs != *rhs
...
3%29bool(rhs) == false
回报false
否则,如果bool(lhs) == false
、回报true
否则返回*lhs < *rhs...
4%29bool(lhs) == false
回报true
否则,如果bool(rhs) == false
、回报false
否则返回*lhs <= *rhs...
5%29bool(lhs) == false
回报false
否则,如果bool(rhs) == false
、回报true
否则返回*lhs > *rhs...
6%29bool(rhs) == false
回报true
否则,如果bool(lhs) == false
、回报false
否则返回*lhs >= *rhs...
7-8%29!opt
...
9-10%29bool(opt)
...
11%29false
...
12%29bool(opt)
...
13%29!opt
...
14%29true
...
15%29bool(opt)
...
16%29false
...
17%29true
...
18%29!opt
...
19%29bool(opt) ? *opt == value : false
...
20%29bool(opt) ? value == *opt : false
...
21%29bool(opt) ? *opt != value : true
...
22%29bool(opt) ? value != *opt : true
...
23%29bool(opt) ? *opt < value : true...
24%29bool(opt) ? value < *opt : false...
25%29bool(opt) ? *opt <= value : true...
26%29bool(opt) ? value <= *opt : false...
27%29bool(opt) ? *opt > value : false...
28%29bool(opt) ? value > *opt : true...
29%29bool(opt) ? *opt >= value : false...
30%29bool(opt) ? value >= *opt : true...
例外
1-6%29%280%29
7-18%29
noexcept
规格:
noexcept
19-30%29%280%29
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。