std::ranges::adjacent_view<V,N>::iterator<Const>::operator++,--,+=,-=
来自 cppreference.cn
< cpp | ranges | adjacent view | iterator
constexpr /*迭代器*/& operator++(); |
(1) | (C++23 起) |
constexpr /*iterator*/ operator++( int ); |
(2) | (C++23 起) |
constexpr /*iterator*/& operator--() requires ranges::bidirectional_range<Base>; |
(3) | (C++23 起) |
constexpr /*iterator*/ operator--( int ) requires ranges::bidirectional_range<Base>; |
(4) | (C++23 起) |
constexpr /*iterator*/& operator+=( difference_type n ) requires ranges::random_access_range<Base>; |
(5) | (C++23 起) |
constexpr /*iterator*/& operator-=( difference_type n ) requires ranges::random_access_range<Base>; |
(6) | (C++23 起) |
自增或自减迭代器。
令 current_
为底层迭代器数组。
1) 等价于若在调用前 current_.back() 不可自增,则行为未定义。
for (auto& i : current_) i = std::ranges::next(i); return *this;
2) 等价于
auto tmp = *this; ++*this; return tmp;
3) 等效于若在调用前 current_.front() 不可自减,则行为未定义。
for (auto& i : current_) i = std::ranges::prev(i); return *this;
4) 等价于
auto tmp = *this; --*this; return tmp;
5) 等同于若在调用前 current_.back() + n 没有良好定义的行为,则行为未定义。
for (auto& i : current_) i = i + n; return *this;
6) 等价于若在调用前 current_.front() - n 没有良好定义的行为,则行为未定义。
for (auto& i : current_) i = i - n; return *this;
目录 |
[编辑] 参数
n | - | 相对于当前位置的偏移量 |
[编辑] 返回值
1,3,5,6) *this
2,4) 改变前 *this 的一个副本。
[编辑] 示例
运行此代码
#include <cassert> #include <list> #include <ranges> #include <utility> #include <vector> 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) |
进行迭代器算术 (公开成员函数) |