[optional.comp.with.t]

# 22 General utilities library [[utilities]](./#utilities)

## 22.5 Optional objects [[optional]](optional#comp.with.t)

### 22.5.9 Comparison with T [optional.comp.with.t]

[ð](#lib:operator==,optional)

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

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5232)

*Constraints*: U is not a specialization of optional[.](#1.sentence-1)

The expression *x == v is well-formed and
its result is convertible to bool[.](#1.sentence-2)

[*Note [1](#note-1)*:

T need not be [*Cpp17EqualityComparable*](utility.arg.requirements#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#1.sentence-3)

â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5241)

*Effects*: Equivalent to: return x.has_value() ? *x == v : false;

[ð](#lib:operator==,optional_)

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

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5252)

*Constraints*: T is not a specialization of optional[.](#3.sentence-1)

The expression v == *x is well-formed and
its result is convertible to bool[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5258)

*Effects*: Equivalent to: return x.has_value() ? v == *x : false;

[ð](#lib:operator!=,optional)

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

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5269)

*Constraints*: U is not a specialization of optional[.](#5.sentence-1)

The expression *x != v is well-formed and
its result is convertible to bool[.](#5.sentence-2)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5275)

*Effects*: Equivalent to: return x.has_value() ? *x != v : true;

[ð](#lib:operator!=,optional_)

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

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5286)

*Constraints*: T is not a specialization of optional[.](#7.sentence-1)

The expression v != *x is well-formed and
its result is convertible to bool[.](#7.sentence-2)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5292)

*Effects*: Equivalent to: return x.has_value() ? v != *x : true;

[ð](#lib:operator%3c,optional)

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

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5303)

*Constraints*: U is not a specialization of optional[.](#9.sentence-1)

The expression *x < v is well-formed and
its result is convertible to bool[.](#9.sentence-2)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5309)

*Effects*: Equivalent to: return x.has_value() ? *x < v : true;

[ð](#lib:operator%3c,optional_)

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

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5320)

*Constraints*: T is not a specialization of optional[.](#11.sentence-1)

The expression v < *x is well-formed and
its result is convertible to bool[.](#11.sentence-2)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5326)

*Effects*: Equivalent to: return x.has_value() ? v < *x : false;

[ð](#lib:operator%3e,optional)

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

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5337)

*Constraints*: U is not a specialization of optional[.](#13.sentence-1)

The expression *x > v is well-formed and
its result is convertible to bool[.](#13.sentence-2)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5343)

*Effects*: Equivalent to: return x.has_value() ? *x > v : false;

[ð](#lib:operator%3e,optional_)

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

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5354)

*Constraints*: T is not a specialization of optional[.](#15.sentence-1)

The expression v > *x is well-formed and
its result is convertible to bool[.](#15.sentence-2)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5360)

*Effects*: Equivalent to: return x.has_value() ? v > *x : true;

[ð](#lib:operator%3c=,optional)

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

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5371)

*Constraints*: U is not a specialization of optional[.](#17.sentence-1)

The expression *x <= v is well-formed and
its result is convertible to bool[.](#17.sentence-2)

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5377)

*Effects*: Equivalent to: return x.has_value() ? *x <= v : true;

[ð](#lib:operator%3c=,optional_)

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

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5388)

*Constraints*: T is not a specialization of optional[.](#19.sentence-1)

The expression v <= *x is well-formed and
its result is convertible to bool[.](#19.sentence-2)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5394)

*Effects*: Equivalent to: return x.has_value() ? v <= *x : false;

[ð](#lib:operator%3e=,optional)

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

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5405)

*Constraints*: U is not a specialization of optional[.](#21.sentence-1)

The expression *x >= v is well-formed and
its result is convertible to bool[.](#21.sentence-2)

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5411)

*Effects*: Equivalent to: return x.has_value() ? *x >= v : false;

[ð](#lib:operator%3e=,optional_)

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

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5422)

*Constraints*: T is not a specialization of optional[.](#23.sentence-1)

The expression v >= *x is well-formed and
its result is convertible to bool[.](#23.sentence-2)

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5428)

*Effects*: Equivalent to: return x.has_value() ? v >= *x : true;

[ð](#lib:operator%3c=%3e,optional)

`template<class T, class U>
    requires (![is-derived-from-optional](optional.syn#concept:is-derived-from-optional "22.5.2 Header <optional> synopsis [optional.syn]")<U>) && [three_way_comparable_with](cmp.concept#concept:three_way_comparable_with "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 U& v);
`

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5442)

*Effects*: Equivalent to: return x.has_value() ? *x <=> v : strong_ordering​::​less;
