std::revers...,+=,--,-,-=(3)
π NAME π
okay so bestie, welcome to the std::revers...,+=,--,-,-=(3) page from the C++ Standard Libary manual β yes, that spelling is what the header says, we're keeping it. The NAME bit is literally:
std::reverse_iterator::operator++,+,+=,--,-,-= -
std::reverse_iterator::operator++,+,+=,--,-,-=
so yeah, it's the whole operator crew for std::reverse_iterator: increment, decrement, plus, minus, plus-equals, minus-equals. iconic behavior, no cap. π
β¨ Synopsis β¨
the manpage formatting turned this synopsis into a little chaos gremlin, but every overload and every (until C++17) / (since C++17) is still here, untouched:
reverse_iterator& (until
operator++(); C++17)
constexpr (since
reverse_iterator& C++17)
operator++();
reverse_iterator& (until
operator--(); C++17)
constexpr (since
reverse_iterator& C++17)
operator--();
reverse_iterator (until
operator++( int ); C++17)
constexpr (since
reverse_iterator C++17)
operator++( int );
reverse_iterator (until
operator--( int ); C++17)
constexpr (since
reverse_iterator C++17)
operator--( int );
reverse_iterator
operator+( (until
difference_type n C++17)
) const;
constexpr
reverse_iterator (since
operator+( C++17)
difference_type n (1)
) const;
reverse_iterator
operator-( (2)
(until
difference_type n
C++17)
) const; (3)
constexpr
reverse_iterator
(since
operator-( (4)
C++17)
difference_type n
) const; (5)
reverse_iterator&
operator+=(
(until
difference_type n
C++17)
);
constexpr (6)
reverse_iterator&
(since
operator+=(
C++17)
difference_type n
); (7)
reverse_iterator&
operator-=(
(until
difference_type n
C++17)
);
constexpr (8)
reverse_iterator&
(since
operator-=(
C++17)
difference_type n
);
Increments or decrements the iterator. Inverse operations are applied to the underlying operator because of the reverse order. π
1,2)Pre-increments or pre-decrements by one respectively.3,4)Post-increments or post-decrements by one respectively.5,6)Returns an iterator which is advanced bynor-npositions respectively.7,8)Advances the iterator bynor-npositions respectively.
πΈ Parameters πΈ
nβ position relative to current location.
π Return value π
1,2)*this3,4)A copy of*thisthat was made before the change.5,6)reverse_iterator(base()-n)orreverse_iterator(base()+n)respectively.7,8)*this
π¦ Example π¦
// Run this code
#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) << '\n'; // 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;
}
and bestie, those last commented-out lines are not a cute little suggestion β they raise compilation error because the underlying iterator does not model the random access iterator. leave them commented, fr fr. π
π Output π
3 4 1 1 4
7 8
π See also π
operator+advances the iterator β function templateoperator-computes the distance between two iterator adaptors β function template
mwah π this page came from http://cppreference.com, and the version/date stamped on it is 2024.06.10. slay. β¨
π¦ 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