constexpr /*iterator*/& operator++(); | (1) | (since C++23) |
constexpr /*iterator*/ operator++( int ); | (2) | (since C++23) |
constexpr /*iterator*/& operator--() requires ranges::bidirectional_range<Base>; | (3) | (since C++23) |
constexpr /*iterator*/ operator--( int ) requires ranges::bidirectional_range<Base>; | (4) | (since C++23) |
constexpr /*iterator*/& operator+=( difference_type n ) requires ranges::random_access_range<Base>; | (5) | (since C++23) |
constexpr /*iterator*/& operator-=( difference_type n ) requires ranges::random_access_range<Base>; | (6) | (since C++23) |
Increments or decrements the iterator.
Let current_
be an underlying array of iterators.
for (auto& i : current_) std::ranges::next(i); return *this;
current_.back()
is not incrementable.auto tmp = *this; ++*this; return tmp;
for (auto& i : current_) std::ranges::prev(i); return *this;
current_.front()
is not decrementable.auto tmp = *this; --*this; return tmp;
for (auto& i : current_) i += n; return *this;
current_.back() + n
does not have well-defined behavior.for (auto& i : current_) i -= n; return *this;
current_.front() - n
does not have well-defined behavior.n | - | position relative to current location |
*this
*this
that was made before the changeA link to test: Compiler Explorer/g++-13.
#include <cassert> #include <list> #include <ranges> #include <utility> #include <vector> [[nodiscard]] bool operator== (std::pair<int&, int&> x, std::pair<int, int> y) { return x.first == y.first and x.second == y.second; } int main() { { auto v = std::vector{0, 1, 2, 3, 4, 5}; auto i = (v | std::views::pairwise).begin(); assert((*i == std::pair{0, 1})); ++i; // overload (1) assert((*i == std::pair{1, 2})); --i; // overload (3) assert((*i == std::pair{0, 1})); i += 2; // overload (5) assert((*i == std::pair{2, 3})); i -= 2; // overload (6) assert((*i == std::pair{0, 1})); } { auto v = std::list{0, 1, 2, 3, 4, 5}; auto i = (v | std::views::pairwise).begin(); assert((*i == std::pair{0, 1})); ++i; // overload (1) assert((*i == std::pair{1, 2})); --i; // overload (3) assert((*i == std::pair{0, 1})); // i += 2; // Error: v is not a random_access_range; overload (5) // i -= 2; // Error: v is not a random_access_range; overload (6) } }
(C++23) | performs iterator arithmetic (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/ranges/adjacent_view/iterator/operator_arith