std::ranges::adjacent_view<V,N>:: iterator <Const>:: operator++,--,+=,-=
From cppreference.net
<
cpp
|
ranges
|
adjacent view
|
iterator
C++
Ranges library
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
std::ranges::adjacent_view
| Member functions | ||||
|
(C++26)
|
||||
| Iterator | ||||
| Member functions | ||||
|
adjacent_view::
iterator
::operator++
adjacent_view:: iterator ::operator++ (int) adjacent_view:: iterator ::operator-- adjacent_view:: iterator ::operator-- (int) adjacent_view:: iterator ::operator+= adjacent_view:: iterator ::operator-= |
||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
|
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)
等价于:
如果调用前
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; // 重载 (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)
|
执行迭代器算术运算
(公开成员函数) |