std::revers...operator*,->(3)
π NAME π
std::reverse_iterator::operator*,-> β that's the whole NAME, bestie. The page also repeats std::reverse_iterator::operator*,-> right after the dash, so we're keeping both because the bit is iconic π
. This is the C++ Standard Libary manual (yes, with the "Libary" spelling, no cap) and the page header is std::revers...operator*,->(3).
πΈ Synopsis πΈ
The synopsis is giving raw source energy β here it is exactly as the page lays it out, version tags, overload numbers, and chaotic C++20 constraint included:
reference operator*() const; (until
C++17)
constexpr reference operator*() const; (since
C++17)
pointer operator->() const;
(until C++17)
constexpr pointer operator->() const;
(since C++17)
(until
C++20)
constexpr pointer operator->() const (1)
(2)
requires (std::is_pointer_v<Iter> ||
(since C++20)
requires (const Iter i) {
i.operator->(); });
This returns a reference or pointer to the element previous to current π«Ά.
1)Equivalent toIter tmp = current; return *--tmp;.2)Equivalent toreturn std::addressof(operator*());. (until C++20)2)(since C++20) Equivalent toreturn current - 1;ifIteris a pointer type.- Otherwise, equivalent to
return std::prev(current).operator->();.
π Parameters π
(none) β literally no parameters, she said what she said π
.
β¨ Return value β¨
Reference or pointer to the element previous to current.
π¦ Example π¦
The page says // Run this code, so here is the code, bestie:
// Run this code
#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";
}
π Output π
*r0 = 3
a[3] = 42
*r1 = 1
vc[2] = (5,6)
π See also π
operator[]β accesses an element by index (public member function).
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::revers...operator*,->(3) πβ¨ bye bestie, go dereference something cute π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms