Making Variant Greater Equal

Document Number: P0393r3, ISO/IEC JTC1 SC22 WG21
Audience:LWG
Date:2016-06-21
Author:Tony Van Eerd (variant at forecode.com)

Motivation

These edits align variant with optional in making the relational operators delegate to the relational operators of the underlying types

drive by fixes:

Other fixes, noticed when editing and/or suggested by LWG during review

?.6 Relational operators [variant.relops]

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

Requires:
get<i>(v) == get<i>(w) is a valid expression returning a type that is convertible to bool, for all i.
Effects:
Equivalent to return (v.valueless_by_exception() && w.valueless_by_exception()) || (v.index() == w.index() && get<i>(v) == get<i>(w) with i being v.index().

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

.
Effects:
Equivalent to return !(v == w).

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

Requires:
get<i>(v) < get<i>(w) is a valid expression returning a type that is convertible to bool, for all i.
Effects:
Equivalent to return (v.index() < w.index()) || (v.index() == w.index() && !v.valueless_by_exception() && get<i>(v) < get<i>(w) with i being v.index().

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

.
Effects:
Equivalent to return w < v.

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

.
Effects:
Equivalent to return !(v > w).

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

.
Effects:
Equivalent to return !(v < w).