Namespaces
Variants

std::ranges::adjacent_view<V,N>:: iterator <Const>:: operator++,--,+=,-=

From cppreference.net
Ranges library
Range adaptors
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)
    }
}

参见

执行迭代器算术运算
(公开成员函数)