function template

std::relational operators (tuple)

<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);
Global relational operator functions for tuple
These overloaded global operator functions perform the appropriate comparison operation between the tuple objects lhs and rhs.

Operations == and != are performed by comparing the elements one by one, stopping at the first mismatch, if any.

Similarly, operations <, >, <= and >= perform a lexicographical comparison on the sequence of individual elements in the tuple.

A lexicographical less-than comparison involves comparing the elements that have the same position in both tuples sequentially from the beginning to the end until one of the following inequalities is true for any pair of elements (with a being the element in lhs and b the element in rhs):
  • if (a<b), then lhs is lower than rhs.
  • if (b<a), then lhs is not lower than rhs.
The comparison stops as soon as one of these inequalities is true.

The types involved in the comparisons are required to have the appropriate relational operator defined for the types being compared: 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>
#include <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.

See also