public member function
<iterator>

std::reverse_iterator::base

iterator_type base() const;
Return base iterator
Returns a copy of the base iterator.

The base iterator is an iterator of the same type as the one used to construct the reverse_iterator, but pointing to the element next to the one the reverse_iterator is currently pointing to (a reverse_iterator has always an offset of -1 with respect to its base iterator).

Parameters

none

Return value

A copy of the base iterator, which iterates in the opposite direction.
Member type iterator_type is the underlying bidirectional iterator type (the class template parameter: Iterator).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// reverse_iterator::base 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;

  std::reverse_iterator<iter_type> rev_end (myvector.begin());
  std::reverse_iterator<iter_type> rev_begin (myvector.end());

  std::cout << "myvector:";
  for (iter_type it = rev_end.base(); it != rev_begin.base(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

Output:

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


Data races

The object is accessed.
The iterator returned can be used to access or modify elements.

Exception safety

Provides the same level of guarantee as the copy constructor of the base iterator.

See also