<tuple>

tuple

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:

comparisonequivalent
a==b
a!=b!(a==b)
a<b
a>bb<a
a>=b!(a<b)
a<=b!(b<a)

Parameters

lhs, rhs
tuple objects (to the left- and right-hand side of the operator, respectively).

Example

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;
}


Output:
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

Return Value

true if the condition holds, and false otherwise.

Data races

Both objects, lhs and rhs, are accessed, and up to all of its members are accessed.
In any case, the function cannot modify its arguments (const-qualified).

Exception safety

If the type of the members supports the appropriate operation with no-throw guarantee, the function never throws exceptions (no-throw guarantee).
If the type of the members do not support being compared with the proper operator, it causes undefined behavior.

See also