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).

参数



返回值

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).

示例

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;
}

输出

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


数据竞争

该对象被访问。
返回的迭代器可用于访问或修改元素。

异常安全

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

另见