function template
<tuple>
std::relational operators (tuple) (1)template<class... TTypes, class... UTypes> bool operator== ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);(2)
template<class... TTypes, class... UTypes> bool operator!= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);(3)
template<class... TTypes, class... UTypes> bool operator< ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);(4)
template<class... TTypes, class... UTypes> bool operator> ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);(5)
template<class... TTypes, class... UTypes> bool operator>= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);(6)
template<class... TTypes, class... UTypes> bool operator<= ( const tuple<TTypes...>& lhs, const tuple<UTypes...>& rhs);
Relational operators for tuple
Performs the appropriate comparison operation between the tuple objects lhs and rhs.Operators ==
and !=
operate comparing the elements one by one (using operator==
), stopping at the first mismatch, if any.
Similarly, operators <
, >
, <=
and >=
perform a lexicographical comparison on the sequence of individual elements in the tuple (using operator<
).
The lexicographical comparison involves comparing the elements that have the same position in both tuples sequentially from the beginning to the end using operator<
reflexively until any such comparison returns true
.
The types involved in the comparisons are required to have the appropriate relational operator defined for the operator: either operator==
(for operator==
and operator!=
) or operator<
(for the other operators). Only those two operator overloads are used to compare elements in a tuple. The other operations are calculated using equivalent results derived from these:
a==b
a!=b
!(a==b)
a<b
a>b
b<a
a>=b
!(a<b)
a<=b
!(b<a)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// tuple relational operators
#include <iostream> // std::cout
#include <tuple> // std::tuple
int main ()
{
std::tuple<int,char> a (10,'x');
std::tuple<char,char> b (10,'x');
std::tuple<char,char> c (10,'y');
if (a==b) std::cout << "a and b are equal\n";
if (b!=c) std::cout << "b and c are not equal\n";
if (b<c) std::cout << "b is less than c\n";
if (c>a) std::cout << "c is greater than a\n";
if (a<=c) std::cout << "a is less than or equal to c\n";
if (c>=b) std::cout << "c is greater than or equal to b\n";
return 0;
}
a and b are equal b and c are not equal b is less than c c is greater than a a is less than or equal to c c is greater than or equal to b
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4