std::reverse_iterator<Iter>::operator*,-> - cppreference.com
From cppreference.com
reference operator*() const; |
(1) | (constexpr since C++17) |
pointer operator->() const; |
(2) | (until C++20) (constexpr since C++17) |
constexpr pointer operator->() const requires (std::is_pointer_v<Iter> || requires (const Iter i) { i.operator->(); }); |
(since C++20) | |
Returns a reference or pointer to the element previous to current.
1) Equivalent to Iter tmp = current; return *--tmp;.
2) Equivalent to:
|
|
(until C++11) |
|
|
(since C++11) (until C++20) |
|
(since C++20) |
Return value
Reference or pointer to the element previous to current.
Example
#include <complex> #include <iostream> #include <iterator> #include <list> 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::list<std::complex<double>>::iterator>; std::list<std::complex<double>> li{{1, 2}, {3, 4}, {5, 6}}; const RI1 r1{li.rbegin()}; std::cout << "*r1 = (" << r1->real() << ',' << r1->imag() << ")\n"; li.insert(li.end(), std::complex<double>{7, 8}); std::cout << "*r1 = (" << r1->real() << ',' << r1->imag() << ")\n"; }
Output:
*r0 = 3 a[3] = 42 *r1 = (5,6) *r1 = (7,8)
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2188 | C++11 | operator-> used & to take address
|
uses std::addressof instead |