operator==,!=,<,<=,>,>=(std::variant) (3) - Linux Manuals

operator==,!=,<,<=,>,>=(std::variant): operator==,!=,<,<=,>,>=(std::variant)

NAME

operator==,!=,<,<=,>,>=(std::variant) - operator==,!=,<,<=,>,>=(std::variant)

Synopsis


Defined in header <variant>
template <class... Types> (1) (since C++17)
constexpr bool operator==(const std::variant<Types...>& v, const std::variant<Types...>& w);
template <class... Types> (2) (since C++17)
constexpr bool operator!=(const std::variant<Types...>& v, const std::variant<Types...>& w);
template <class... Types> (3) (since C++17)
constexpr bool operator<(const std::variant<Types...>& v, const std::variant<Types...>& w);
template <class... Types> (4) (since C++17)
constexpr bool operator>(const std::variant<Types...>& v, const std::variant<Types...>& w);
template <class... Types> (5) (since C++17)
constexpr bool operator<=(const std::variant<Types...>& v, const std::variant<Types...>& w);
template <class... Types> (6) (since C++17)
constexpr bool operator>=(const std::variant<Types...>& v, const std::variant<Types...>& w);


1) Equality operator for variants:


* If v.index() != w.index(), returns false;
* otherwise if v.valueless_by_exception(), returns true;
* otherwise returns std::get<v.index()>(v) == std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) == std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.


2) Inequality operator for variants:


* If v.index() != w.index(), returns true;
* otherwise if v.valueless_by_exception(), returns false;
* otherwise returns std::get<v.index()>(v) != std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) != std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.


3) Less-than operator for variants:


* If w.valueless_by_exception(), returns false;
* otherwise if v.valueless_by_exception(), returns true;
* otherwise if v.index() < w.index(), returns true;
* otherwise if v.index() > w.index(), returns false;
* otherwise returns std::get<v.index()>(v) < std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) < std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.


4) Greater-than operator for variants:


* If v.valueless_by_exception(), returns false;
* otherwise if w.valueless_by_exception(), returns true;
* otherwise if v.index() > w.index(), returns true;
* otherwise if v.index() < w.index(), returns false;
* otherwise returns std::get<v.index()>(v) > std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) > std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.


5) Less-equal operator for variants:


* If v.valueless_by_exception(), returns true;
* otherwise if w.valueless_by_exception(), returns false;
* otherwise if v.index() < w.index(), returns true;
* otherwise if v.index() > w.index(), returns false;
* otherwise returns std::get<v.index()>(v) <= std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) <= std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.


6) Greater-equal operator for variants:


* If w.valueless_by_exception(), returns true;
* otherwise if v.valueless_by_exception(), returns false;
* otherwise if v.index() > w.index(), returns true;
* otherwise if v.index() < w.index(), returns false;
* otherwise std::get<v.index()>(v) >= std::get<v.index()>(w). The behavior is undefined if std::get<i>(v) >= std::get<i>(w) is not a valid expression returning a type convertible to bool, for any i.

Parameters


v,w - variants to compare

Return value


The boolean result of the comparison as described above.

Example


 This section is incomplete
 Reason: no example

See also


operator==
operator!=
operator< compares optional objects
operator<= (function template)
operator>
operator>=


(C++17)