[optional.relops] (original) (raw)

22 General utilities library [utilities]

22.5 Optional objects [optional]

22.5.6 Relational operators [optional.relops]

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

Constraints: The expression *x == *y is well-formed and its result is convertible to bool.

Returns: If x.has_value() != y.has_value(), false; otherwise if x.has_value() == false, true; otherwise *x == *y.

Remarks: Specializations of this function template for which *x == *y is a core constant expression are constexpr functions.

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

Constraints: The expression *x != *y is well-formed and its result is convertible to bool.

Returns: If x.has_value() != y.has_value(), true; otherwise, if x.has_value() == false, false; otherwise *x != *y.

Remarks: Specializations of this function template for which *x != *y is a core constant expression are constexpr functions.

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

Constraints: *x < *y is well-formed and its result is convertible to bool.

Returns: If !y, false; otherwise, if !x, true; otherwise *x < *y.

Remarks: Specializations of this function template for which *x < *y is a core constant expression are constexpr functions.

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

Constraints: The expression *x > *y is well-formed and its result is convertible to bool.

Returns: If !x, false; otherwise, if !y, true; otherwise *x > *y.

Remarks: Specializations of this function template for which *x > *y is a core constant expression are constexpr functions.

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

Constraints: The expression *x <= *y is well-formed and its result is convertible to bool.

Returns: If !x, true; otherwise, if !y, false; otherwise *x <= *y.

Remarks: Specializations of this function template for which *x <= *y is a core constant expression are constexpr functions.

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

Constraints: The expression *x >= *y is well-formed and its result is convertible to bool.

Returns: If !y, true; otherwise, if !x, false; otherwise *x >= *y.

Remarks: Specializations of this function template for which *x >= *y is a core constant expression are constexpr functions.

template<class T, [three_way_comparable_with](cmp.concept#concept:three%5Fway%5Fcomparable%5Fwith "17.12.4 Concept three_­way_­comparable [cmp.concept]")<T> U> constexpr compare_three_way_result_t<T, U> operator<=>(const optional<T>& x, const optional<U>& y);

Returns: If x && y, *x <=> *y; otherwise x.has_value() <=> y.has_value().

Remarks: Specializations of this function template for which *x <=> *y is a core constant expression are constexpr functions.