Files
cppdraft_translate/cppdraft/variant/relops.md
2025-10-25 03:02:53 +03:00

5.4 KiB
Raw Blame History

[variant.relops]

22 General utilities library [utilities]

22.6 Variants [variant]

22.6.6 Relational operators [variant.relops]

🔗

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

1

#

Constraints: GET(v) == GET(w) is a valid expression that is convertible to bool, for all i.

2

#

Returns: If v.index() != w.index(), false; otherwise if v.valueless_by_exception(), true; otherwise GET(v) == GET(w) with i being v.index().

🔗

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

3

#

Constraints: GET(v) != GET(w) is a valid expression that is convertible to bool, for all i.

4

#

Returns: If v.index() != w.index(), true; otherwise if v.valueless_by_exception(), false; otherwise GET(v) != GET(w) with i being v.index().

🔗

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

5

#

Constraints: GET(v) < GET(w) is a valid expression that is convertible to bool, for all i.

6

#

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(v) < GET(w) with i being v.index().

🔗

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

7

#

Constraints: GET(v) > GET(w) is a valid expression that is convertible to bool, for all i.

8

#

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(v) > GET(w) with i being v.index().

🔗

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

9

#

Constraints: GET(v) <= GET(w) is a valid expression that is convertible to bool, for all i.

10

#

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(v) <= GET(w) with i being v.index().

🔗

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

11

#

Constraints: GET(v) >= GET(w) is a valid expression that is convertible to bool, for all i.

12

#

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(v) >= GET(w) with i being v.index().

🔗

template<class... Types> requires ([three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4Concept 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

#

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(v) <=> GET(w); with i being v.index().