[optional.relops] # 22 General utilities library [[utilities]](./#utilities) ## 22.5 Optional objects [[optional]](optional#relops) ### 22.5.7 Relational operators [optional.relops] [🔗](#lib:operator==,optional) `template constexpr bool operator==(const optional& x, const optional& y); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5042) *Constraints*: The expression *x == *y is well-formed and its result is convertible to bool[.](#1.sentence-1) [*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-2) — *end note*] [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5050) *Returns*: If x.has_value() != y.has_value(), false; otherwise if x.has_value() == false, true; otherwise *x == *y[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5054) *Remarks*: Specializations of this function template for which *x == *y is a core constant expression are constexpr functions[.](#3.sentence-1) [🔗](#lib:operator!=,optional) `template constexpr bool operator!=(const optional& x, const optional& y); ` [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5067) *Constraints*: The expression *x != *y is well-formed and its result is convertible to bool[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5072) *Returns*: If x.has_value() != y.has_value(), true; otherwise, if x.has_value() == false, false; otherwise *x != *y[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5078) *Remarks*: Specializations of this function template for which *x != *y is a core constant expression are constexpr functions[.](#6.sentence-1) [🔗](#lib:operator%3c,optional) `template constexpr bool operator<(const optional& x, const optional& y); ` [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5091) *Constraints*: *x < *y is well-formed and its result is convertible to bool[.](#7.sentence-1) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5096) *Returns*: If !y, false; otherwise, if !x, true; otherwise *x < *y[.](#8.sentence-1) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5102) *Remarks*: Specializations of this function template for which *x < *y is a core constant expression are constexpr functions[.](#9.sentence-1) [🔗](#lib:operator%3e,optional) `template constexpr bool operator>(const optional& x, const optional& y); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5115) *Constraints*: The expression *x > *y is well-formed and its result is convertible to bool[.](#10.sentence-1) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5120) *Returns*: If !x, false; otherwise, if !y, true; otherwise *x > *y[.](#11.sentence-1) [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5126) *Remarks*: Specializations of this function template for which *x > *y is a core constant expression are constexpr functions[.](#12.sentence-1) [🔗](#lib:operator%3c=,optional) `template constexpr bool operator<=(const optional& x, const optional& y); ` [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5139) *Constraints*: The expression *x <= *y is well-formed and its result is convertible to bool[.](#13.sentence-1) [14](#14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5144) *Returns*: If !x, true; otherwise, if !y, false; otherwise *x <= *y[.](#14.sentence-1) [15](#15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5150) *Remarks*: Specializations of this function template for which *x <= *y is a core constant expression are constexpr functions[.](#15.sentence-1) [🔗](#lib:operator%3e=,optional) `template constexpr bool operator>=(const optional& x, const optional& y); ` [16](#16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5163) *Constraints*: The expression *x >= *y is well-formed and its result is convertible to bool[.](#16.sentence-1) [17](#17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5168) *Returns*: If !y, true; otherwise, if !x, false; otherwise *x >= *y[.](#17.sentence-1) [18](#18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5174) *Remarks*: Specializations of this function template for which *x >= *y is a core constant expression are constexpr functions[.](#18.sentence-1) [🔗](#lib:operator%3c=%3e,optional) `template U> constexpr compare_three_way_result_t operator<=>(const optional& x, const optional& y); ` [19](#19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5189) *Returns*: If x && y, *x <=> *y; otherwise x.has_value() <=> y.has_value()[.](#19.sentence-1) [20](#20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L5193) *Remarks*: Specializations of this function template for which *x <=> *y is a core constant expression are constexpr functions[.](#20.sentence-1)