public member function
<iterator>

std::reverse_iterator::operator*

reference operator*() const;
Dereference iterator
Returns a reference to the element pointed to by the iterator.

Internally, the function decreases a copy of its base iterator and returns the result of dereferencing it.

The iterator shall point to some object in order to be dereferenceable.

参数



返回值

A reference to the element pointed by the iterator.
Member type reference is an alias of the base iterator's own reference type.

示例

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

输出

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


数据竞争

该对象被访问。
The reference returned can be used to access or modify elements.

异常安全

提供与应用于*基迭代器*的操作相同的保证级别。

另见