function template
<iterator>

std::relational operators (reverse_iterator)

(1)
template <class Iterator>  bool operator== (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(2)
template <class Iterator>  bool operator!= (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(3)
template <class Iterator>  bool operator<  (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(4)
template <class Iterator>  bool operator<= (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(5)
template <class Iterator>  bool operator>  (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(6)
template <class Iterator>  bool operator>= (const reverse_iterator<Iterator>& lhs,                   const reverse_iterator<Iterator>& rhs);
(1)
template <class Iterator1, class Iterator2>  bool operator== (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
(2)
template <class Iterator1, class Iterator2>  bool operator!= (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
(3)
template <class Iterator1, class Iterator2>  bool operator<  (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
(4)
template <class Iterator1, class Iterator2>  bool operator<= (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
(5)
template <class Iterator1, class Iterator2>  bool operator>  (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
(6)
template <class Iterator1, class Iterator2>  bool operator>= (const reverse_iterator<Iterator1>& lhs,                   const reverse_iterator<Iterator2>& rhs);
Relational operators for reverse_iterator
Performs the appropriate comparison operation between the reverse_iterator objects lhs and rhs.

Internally, the function compares directly the base iterators using the reflexively equivalent relational operator:

operator on
reverse iterators
equivalent used on
base iterators
====
!=!=
< >
<=>=
> <
>=<=

These operators are overloaded in header <iterator>.

Parameters

lhs, rhs
reverse_iterator objects (to the left- and right-hand side of the operator, respectively), having both the same template parameter (Iterator).
reverse_iterator objects (to the left- and right-hand side of the operator, respectively) for whose base iterators the proper comparison operation is defined.

Return Value

true if the condition holds, and false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// reverse_iterator example
#include <iostream>     // std::cout
#include <iterator>     // std::reverse_iterator
#include <vector>       // std::vector

int main () {
  std::vector<int> myvector;
  for (int i=0; i<10; i++) myvector.push_back(i);

  typedef std::vector<int>::iterator iter_type;
                                                         // ? 9 8 7 6 5 4 3 2 1 0 ?
  iter_type from (myvector.begin());                     //   ^
                                                         //         ------>
  iter_type until (myvector.end());                      //                       ^
                                                         //
  std::reverse_iterator<iter_type> rev_until (from);     // ^
                                                         //         <------
  std::reverse_iterator<iter_type> rev_from (until);     //                     ^

  std::cout << "myvector:";
  while (rev_from != rev_until)
    std::cout << ' ' << *rev_from++;
  std::cout << '\n';

  return 0;
}

Output:
myvector: 9 8 7 6 5 4 3 2 1 0


Data races

Both objects, lhs and rhs, are accessed.

Exception safety

Provides the same level of guarantee as the operation applied to the base iterators of lhs and rhs.

See also