[variant.relops]

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

## 22.6 Variants [[variant]](variant#relops)

### 22.6.6 Relational operators [variant.relops]

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

`template<class... Types>
  constexpr bool operator==(const variant<Types...>& v, const variant<Types...>& w);
`

[1](#1)

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

*Constraints*: *GET*<i>(v) == *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#1.sentence-1)

[2](#2)

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

*Returns*: If v.index() != w.index(), false;
otherwise if v.valueless_by_exception(), true;
otherwise *GET*<i>(v) == *GET*<i>(w) with i being v.index()[.](#2.sentence-1)

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

`template<class... Types>
  constexpr bool operator!=(const variant<Types...>& v, const variant<Types...>& w);
`

[3](#3)

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

*Constraints*: *GET*<i>(v) != *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#3.sentence-1)

[4](#4)

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

*Returns*: If v.index() != w.index(), true;
otherwise if v.valueless_by_exception(), false;
otherwise *GET*<i>(v) != *GET*<i>(w) with i being v.index()[.](#4.sentence-1)

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

`template<class... Types>
  constexpr bool operator<(const variant<Types...>& v, const variant<Types...>& w);
`

[5](#5)

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

*Constraints*: *GET*<i>(v) < *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#5.sentence-1)

[6](#6)

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

*Returns*: If w.valueless_by_exception(), false;
otherwise if v.valueless_by_exception(), true;
otherwise, if v.index() < w.index(), true;
otherwise if v.index() > w.index(), false;
otherwise *GET*<i>(v) < *GET*<i>(w) with i being v.index()[.](#6.sentence-1)

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

`template<class... Types>
  constexpr bool operator>(const variant<Types...>& v, const variant<Types...>& w);
`

[7](#7)

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

*Constraints*: *GET*<i>(v) > *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#7.sentence-1)

[8](#8)

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

*Returns*: If v.valueless_by_exception(), false;
otherwise if w.valueless_by_exception(), true;
otherwise, if v.index() > w.index(), true;
otherwise if v.index() < w.index(), false;
otherwise *GET*<i>(v) > *GET*<i>(w) with i being v.index()[.](#8.sentence-1)

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

`template<class... Types>
  constexpr bool operator<=(const variant<Types...>& v, const variant<Types...>& w);
`

[9](#9)

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

*Constraints*: *GET*<i>(v) <= *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#9.sentence-1)

[10](#10)

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

*Returns*: If v.valueless_by_exception(), true;
otherwise if w.valueless_by_exception(), false;
otherwise, if v.index() < w.index(), true;
otherwise if v.index() > w.index(), false;
otherwise *GET*<i>(v) <= *GET*<i>(w) with i being v.index()[.](#10.sentence-1)

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

`template<class... Types>
  constexpr bool operator>=(const variant<Types...>& v, const variant<Types...>& w);
`

[11](#11)

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

*Constraints*: *GET*<i>(v) >= *GET*<i>(w) is a valid expression that is
convertible to bool, for all i[.](#11.sentence-1)

[12](#12)

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

*Returns*: If w.valueless_by_exception(), true;
otherwise if v.valueless_by_exception(), false;
otherwise, if v.index() > w.index(), true;
otherwise if v.index() < w.index(), false;
otherwise *GET*<i>(v) >= *GET*<i>(w) with i being v.index()[.](#12.sentence-1)

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

`template<class... Types> requires ([three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4 Concept three_­way_­comparable [cmp.concept]")<Types> && ...)
  constexpr common_comparison_category_t<compare_three_way_result_t<Types>...>
    operator<=>(const variant<Types...>& v, const variant<Types...>& w);
`

[13](#13)

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

*Effects*: Equivalent to:if (v.valueless_by_exception() && w.valueless_by_exception())return strong_ordering::equal;if (v.valueless_by_exception()) return strong_ordering::less;if (w.valueless_by_exception()) return strong_ordering::greater;if (auto c = v.index() <=> w.index(); c != 0) return c;return *GET*<i>(v) <=> *GET*<i>(w); with i being v.index()[.](#13.sentence-1)
