std::ranges::adjacent_view<V,N>::iterator<Const>::operator++,--,+=,-=
来自 zh.cppreference.net
constexpr /*iterator*/& 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) 等价于:
如果调用前该
for (auto& i : current_)
i = std::ranges::next(i);
return *this;
current_.back()不可递增,则行为未定义。2) 等价于:
auto tmp = *this;
++*this;
return tmp;
3) 等价于:
如果调用前该
for (auto& i : current_)
i = std::ranges::prev(i);
return *this;
current_.front()不可递减,则行为未定义。4) 等价于:
auto tmp = *this;
--*this;
return tmp;
5) 等价于:
如果调用前该
for (auto& i : current_)
i = i + n;
return *this;
current_.back() + n不具有良好定义的行为,则行为未定义。6) 等价于:
如果调用前该
for (auto& i : current_)
i = i - n;
return *this;
current_.front() - n不具有良好定义的行为,则行为未定义。参数
| 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; // 重载 (1) assert((*i == std::pair{1, 2})); --i; // 重载 (3) assert((*i == std::pair{0, 1})); i += 2; // 重载 (5) assert((*i == std::pair{2, 3})); i -= 2; // 重载 (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; // 重载 (1) assert((*i == std::pair{1, 2})); --i; // 重载 (3) assert((*i == std::pair{0, 1})); // i += 2; // 错误:v 不是 random_access_range;重载 (5) // i -= 2; // 错误:v 不是 random_access_range;重载 (6) } }
参见
|
(C++23)
|
执行迭代器算术运算
(公开成员函数) |