function template
<array>

std::relational operators (array)

(1)
template <class T, size_T N>
  bool operator== ( const array<T,N>& lhs, const array<T,N>& rhs );
(2)
template <class T, size_T N>
  bool operator!= ( const array<T,N>& lhs, const array<T,N>& rhs );
(3)
template <class T, size_T N>
  bool operator<  ( const array<T,N>& lhs, const array<T,N>& rhs );
(4)
template <class T, size_T N>
  bool operator<= ( const array<T,N>& lhs, const array<T,N>& rhs );
(5)
template <class T, size_T N>
  bool operator>  ( const array<T,N>& lhs, const array<T,N>& rhs );
(6)
template <class T, size_T N>
  bool operator>= ( const array<T,N>& lhs, const array<T,N>& rhs );
Relational operators for array
Performs the appropriate comparison operation between the array containers lhs and rhs.

Operations == and != are performed by comparing the elements one by one using algorithm equal, stopping at the first mismatch.

Operations <, >, <= and >= behave as if using algorithm lexicographical_compare, which compares the elements sequentially using operator< reflexively, stopping at the first mismatch.

These operators are overloaded in header <array>.

Parameters

lhs, rhs
array containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (T and N).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// array comparisons
#include <iostream>
#include <array>

int main ()
{
  std::array<int,5> a = {10, 20, 30, 40, 50};
  std::array<int,5> b = {10, 20, 30, 40, 50};
  std::array<int,5> c = {50, 40, 30, 20, 10};

  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>b) std::cout << "c is greater than b\n";
  if (a<=b) std::cout << "a is less than or equal to b\n";
  if (a>=b) std::cout << "a 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 b
a is less than or equal to b
a is greater than or equal to b

Return Value

true if the condition holds, and false otherwise.

Complexity

Linear in both lhs and rhs's sizes.

Iterator validity

No changes.

Data races

Up to all of the elements contained in both lhs and rhs may be accessed.

Exception safety

If the type of the elements supports the appropriate operation with no-throw guarantee, the function never throws exceptions (no-throw guarantee).
In any case, the function cannot modify its arguments.

See also