命名空间
变体
操作

std::reverse_iterator<Iter>::operator*,->

来自 cppreference.cn
 
 
迭代器库
迭代器概念
迭代器原语
算法概念与工具
间接可调用概念
常用算法要求
(C++20)
(C++20)
(C++20)
工具
(C++20)
迭代器适配器
范围访问
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
 
reference operator*() const;
(1) (自 C++17 起为 constexpr)
(2)
pointer operator->() const;
(自 C++17 起为 constexpr)
(C++20 前)
constexpr pointer operator->() const

    requires (std::is_pointer_v<Iter> ||

              requires (const Iter i) { i.operator->(); });
(C++20 起)

返回一个引用或指向 `current` 前一个元素的指针。

 成员函数  等价于
operator* Iter tmp = current; return *--tmp;
operator->

return &(operator*());

(C++11 前)

return std::addressof(operator*());

(C++11 起)
(C++20 前)
(C++20 起)

目录

[edit] 返回值

如上所述。

[edit] 示例

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

[edit] 缺陷报告

下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。

缺陷报告 应用于 发布时的行为 正确的行为
LWG 2188 C++11 operator-> 使用 & 取地址 改为使用 std::addressof

[edit] 参阅

通过索引访问元素
(public member function) [编辑]