std::reverse_iterator<Iter>::operator*,->
来自 cppreference.com
< cpp | iterator | reverse iterator
(1) | ||
引用运算符*() const; |
(直到 C++17) | |
constexpr 引用运算符*() const; |
(自 C++17 起) | |
(2) | ||
指针运算符->() const; |
(直到 C++17) | |
constexpr 指针运算符->() const; |
(自 C++17 起) (直到 C++20) |
|
constexpr 指针运算符->() const requires (std::is_pointer_v<Iter> || |
(自 C++20 起) | |
返回对 current
之前元素的引用或指针。
1) 等同于 Iter tmp = current; return *--tmp;.
2) 等同于 return std::addressof(operator*());. |
(直到 C++20) |
(自 C++20 起) |
内容 |
[编辑] 参数
(无)
[编辑] 返回值
对 current
之前元素的引用或指针。
[编辑] 示例
运行此代码
#include <complex> #include <iostream> #include <iterator> #include <vector> int main() { using RI0 = std::reverse_iterator<int*>; int a[]{0, 1, 2, 3}; RI0 r0{std::rbegin(a)}; std::cout << "*r0 = " << *r0 << '\n'; *r0 = 42; std::cout << "a[3] = " << a[3] << '\n'; using RI1 = std::reverse_iterator<std::vector<int>::iterator>; std::vector<int> vi{0, 1, 2, 3}; RI1 r1{vi.rend() - 2}; std::cout << "*r1 = " << *r1 << '\n'; using RI2 = std::reverse_iterator<std::vector<std::complex<double>>::iterator>; std::vector<std::complex<double>> vc{{1,2}, {3,4}, {5,6}, {7,8}}; RI2 r2{vc.rbegin() + 1}; std::cout << "vc[2] = (" << r2->real() << ',' << r2->imag() << ")\n"; }
输出
*r0 = 3 a[3] = 42 *r1 = 1 vc[2] = (5,6)
[编辑] 另请参阅
通过索引访问元素 (公共成员函数) |