<optional> 运算符

operator==

测试运算符左侧的 optional 对象是否等于右侧的 optional 对象。

template <class T, class U> constexpr bool operator==(const optional<T>& left, const optional<U>& right);
template <class T> constexpr bool operator==(const optional<T>& left, nullopt_t right) noexcept;
template <class T> constexpr bool operator==(nullopt_t left, const optional<T>& right) noexcept;
template <class T, class U> constexpr bool operator==(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator==(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

operator!=

测试运算符左侧的 optional 对象是否不等于右侧的 optional 对象。

template <class T, class U> constexpr bool operator!=(const optional<T>&, const optional<U>&);
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator!=(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

备注

此模板函数返回 !(left == right)

operator<

测试运算符左侧的 optional 对象是否小于右侧的 optional 对象。

template <class T, class U> constexpr bool operator<(const optional<T>&, const optional<U>&);
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
template <class T, class U> constexpr bool operator<(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator<(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

返回值

如果运算符左侧的列表小于但不等于运算符右侧的列表,则为 true,否则为 false

operator<=

测试运算符左侧的 optional 对象是否小于或等于右侧的 optional 对象。

template <class T, class U> constexpr bool operator<=(const optional<T>&, const optional<U>&);
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator<=(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

返回值

如果运算符左侧的列表小于或等于运算符右侧的列表,则为 true,否则为 false

注解

此模板函数返回 !(right < left)

operator>

测试运算符左侧的 optional 对象是否大于右侧的 optional 对象。

template <class T, class U> constexpr bool operator>(const optional<T>&, const optional<U>&);
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
template <class T, class U> constexpr bool operator>(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator>(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

返回值

如果运算符左侧的列表大于运算符右侧的列表,则为 true,否则为 false

注解

此模板函数返回 right < left

operator>=

测试运算符左侧的 optional 对象是否大于或等于右侧的 optional 对象。

template <class T, class U> constexpr bool operator>=(const optional<T>&, const optional<U>&);
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator>=(const U&, const optional<T>&);

参数

left
类型 optionalnullopt_tT 的对象。

right
类型 optionalnullopt_tT 的对象。

返回值

如果运算符左侧的 optional 大于或等于右侧的 optional,则为 true;否则为 false

注解

此模板函数返回 !(left < right)