Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | utility‎ | variant
 
 
 
 
Defined in header <variant>
template <class... Types>
constexpr bool operator==(const std::variant<Types...>& v, std::const variant<Types...>& w);
(1) (since C++17)
template <class... Types>
constexpr bool operator!=(const std::variant<Types...>& v, const std::variant<Types...>& w);
(2) (since C++17)
template <class... Types>
constexpr bool operator<(const std::variant<Types...>& v, const std::variant<Types...>& w);
(3) (since C++17)
template <class... Types>
constexpr bool operator>(const std::variant<Types...>& v, const std::variant<Types...>& w);
(4) (since C++17)
template <class... Types>
constexpr bool operator<=(const std::variant<Types...>& v, const std::variant<Types...>& w);
(5) (since C++17)
template <class... Types>
constexpr bool operator>=(const std::variant<Types...>& v, const std::variant<Types...>& w);
(6) (since C++17)
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) == 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 get<v.index()>(v) != 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 get<v.index()>(v) < 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 {{{1}}}. 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.

Contents

[edit] Parameters

v,w - variants to compare

[edit] Return value

The boolean result of the comparison as described above.

[edit] Example

[edit] See also

compares optional objects
(function template) [edit]