operator==, !=, <, <=, >, >=(std::variant)
Defined in header <variant> | ||
---|---|---|
template <class... Types> constexpr bool operator==(const std::variant<Types...>& v, const std::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) |
- If
v.index() != w.index()
, returnsfalse
; - otherwise if
v.valueless_by_exception()
, returnstrue
; - otherwise returns
std::get<v.index()>(v) == std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) == std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
- If
v.index() != w.index()
, returnstrue
; - otherwise if
v.valueless_by_exception()
, returnsfalse
; - otherwise returns
std::get<v.index()>(v) != std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) != std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
- If
w.valueless_by_exception()
, returnsfalse
; - otherwise if
v.valueless_by_exception()
, returnstrue
; - otherwise if
v.index() < w.index()
, returnstrue
; - otherwise if
v.index() > w.index()
, returnsfalse
; - otherwise returns
std::get<v.index()>(v) < std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) < std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
- If
v.valueless_by_exception()
, returnsfalse
; - otherwise if
w.valueless_by_exception()
, returnstrue
; - otherwise if
v.index() > w.index()
, returnstrue
; - otherwise if
v.index() < w.index()
, returnsfalse
; - otherwise returns
std::get<v.index()>(v) > std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) > std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
- If
v.valueless_by_exception()
, returnstrue
; - otherwise if
w.valueless_by_exception()
, returnsfalse
; - otherwise if
v.index() < w.index()
, returnstrue
; - otherwise if
v.index() > w.index()
, returnsfalse
; - otherwise returns
std::get<v.index()>(v) <= std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) <= std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
- If
w.valueless_by_exception()
, returnstrue
; - otherwise if
v.valueless_by_exception()
, returnsfalse
; - otherwise if
v.index() > w.index()
, returnstrue
; - otherwise if
v.index() < w.index()
, returnsfalse
; - otherwise
std::get<v.index()>(v) >= std::get<v.index()>(w)
. The behavior is undefined ifstd::get<i>(v) >= std::get<i>(w)
is not a valid expression returning a type convertible to bool, for anyi
.
Parameters
v,w | - | variants to compare |
Return value
The boolean result of the comparison as described above.
Example
See also
(C++17) | compares optional objects (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/variant/operator_cmp