Difference between revisions of "cpp/utility/variant/operator cmp"
From cppreference.com
m (link to ja) |
(fmt) |
||
Line 4: | Line 4: | ||
{{dcl header | variant}} | {{dcl header | variant}} | ||
{{dcl | since=c++17 | num=1 |1= | {{dcl | since=c++17 | num=1 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator==(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator==( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl | since=c++17 | num=2 |1= | {{dcl | since=c++17 | num=2 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator!=(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator!=( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl | since=c++17 | num=3 |1= | {{dcl | since=c++17 | num=3 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator<(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator<( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl | since=c++17 | num=4 |1= | {{dcl | since=c++17 | num=4 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator>(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator>( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl | since=c++17 | num=5 |1= | {{dcl | since=c++17 | num=5 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator<=(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator<=( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl | since=c++17 | num=6 |1= | {{dcl | since=c++17 | num=6 |1= | ||
− | template <class... Types> | + | template< class... Types > |
− | constexpr bool operator>=(const std::variant<Types...>& v, const std::variant<Types...>& w); | + | constexpr bool operator>=( const std::variant<Types...>& v, |
+ | const std::variant<Types...>& w ); | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} |
Revision as of 15:11, 29 October 2019
Defined in header <variant>
|
||
template< class... Types > constexpr bool operator==( const std::variant<Types...>& v, |
(1) | (since C++17) |
template< class... Types > constexpr bool operator!=( const std::variant<Types...>& v, |
(2) | (since C++17) |
template< class... Types > constexpr bool operator<( const std::variant<Types...>& v, |
(3) | (since C++17) |
template< class... Types > constexpr bool operator>( const std::variant<Types...>& v, |
(4) | (since C++17) |
template< class... Types > constexpr bool operator<=( const std::variant<Types...>& v, |
(5) | (since C++17) |
template< class... Types > constexpr bool operator>=( const std::variant<Types...>& v, |
(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) == 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
.
Contents |
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
(C++17)(C++17)(C++17)(C++17)(C++17)(C++17)(C++20) |
compares optional objects (function template) |