在线文档教程
C++
应用 | Utilities

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物体,lhsrhs使用相应的运算符将所包含的值%28进行比较。T%29只有当两者兼而有之时lhsrhs包含值。否则,

  • lhs被认为等于rhs当且仅当lhsrhs不包含值。

  • lhs被认为少于rhs如果,而且只有在这样的情况下,rhs包含一个值和lhs不会的。

7-18%29比较opt带着nullopt值等于%281-6%29。optional它不包含值。

19-30%29比较opt带着value。使用相应的运算符将值%28进行比较。T%29只在以下情况下opt包含一个值。否则,opt被认为少于value。如果对应的比较表达式*optvalue格式不正确,或者如果其结果不能转换为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。

http://en.cppreference.com/w/cpp/实用程序/可选/操作符[医]CMP