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:

comparison

equivalent

a==b

a!=b

!(a==b)

a<b

a>b

b<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

12345678910111213141516171819

// tuple relational operators#include <iostream> // std::cout#include <tuple> // std::tupleint 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.