(1) | ||
reverse_iterator& operator++(); | (until C++17) | |
constexpr reverse_iterator& operator++(); | (since C++17) | |
(2) | ||
reverse_iterator& operator--(); | (until C++17) | |
constexpr reverse_iterator& operator--(); | (since C++17) | |
(3) | ||
reverse_iterator operator++( int ); | (until C++17) | |
constexpr reverse_iterator operator++( int ); | (since C++17) | |
(4) | ||
reverse_iterator operator--( int ); | (until C++17) | |
constexpr reverse_iterator operator--( int ); | (since C++17) | |
(5) | ||
reverse_iterator operator+( difference_type n ) const; | (until C++17) | |
constexpr reverse_iterator operator+( difference_type n ) const; | (since C++17) | |
(6) | ||
reverse_iterator operator-( difference_type n ) const; | (until C++17) | |
constexpr reverse_iterator operator-( difference_type n ) const; | (since C++17) | |
(7) | ||
reverse_iterator& operator+=( difference_type n ); | (until C++17) | |
constexpr reverse_iterator& operator+=( difference_type n ); | (since C++17) | |
(8) | ||
reverse_iterator& operator-=( difference_type n ); | (until C++17) | |
constexpr reverse_iterator& operator-=( difference_type n ); | (since C++17) |
Increments or decrements the iterator. Inverse operations are applied to the underlying operator because of the reverse order.
n
or -n
positions respectively.n
or -n
positions respectively.n | - | position relative to current location. |
*this
.*this
that was made before the change.reverse_iterator(base()-n)
or reverse_iterator(base()+n)
respectively.*this
.#include <iostream> #include <iterator> #include <list> #include <vector> int main() { std::vector v {0, 1, 2, 3, 4}; auto rv = std::reverse_iterator {v.rbegin()}; std::cout << *(++rv) << ' '; // 3 std::cout << *(--rv) << ' '; // 4 std::cout << *(rv + 3) << ' '; // 1 rv += 3; std::cout << rv[0] << ' '; // 1 rv -= 3; std::cout << rv[0] << '\n'; // 4 std::list l {5, 6, 7, 8}; auto rl = std::reverse_iterator {l.rbegin()}; std::cout << *(++rl) << ' '; // OK: 3 std::cout << *(--rl) << ' '; // OK: 4 // The following statements raise compilation error because the // underlying iterator does not model the random access iterator: // *(rl + 3) = 13; // rl += 3; // rl -= 3; }
Output:
3 4 1 1 4 7 8
advances the iterator (function template) |
|
computes the distance between two iterator adaptors (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/iterator/reverse_iterator/operator_arith