命名空间
变体
操作

std::ranges::subrange<I,S,K>::next

来自 cppreference.cn
< cpp‎ | ranges‎ | subrange
 
 
范围库
范围适配器
 
 
constexpr subrange next( std::iter_difference_t<I> n = 1 ) const&
    requires std::forward_iterator<I>;
(1) (since C++20)
constexpr subrange next( std::iter_difference_t<I> n = 1 ) &&;
(2) (since C++20)

返回一个 subrange,其 begin_ 被递增(如果 n 为负数则递减)。实际的递增(或递减)操作由 advance() 执行。

1) 返回 *this 的副本。
等价于: auto tmp = *this;
tmp.advance(n);
return tmp;
2) 返回从 *this 移动的 subrange
等价于: advance(n);
return std::move(*this);

目录

[edit] 参数

n - 迭代器的最大递增次数

[edit] 返回值

如上所述。

[edit] 注释

此函数与 advance() 的区别在于后者执行就地递增(或递减)。

[edit] 示例

#include <array>
#include <iterator>
#include <print>
#include <ranges>
 
int main()
{
    std::array arr{1, 2, 3, 4, 5, 6, 7};
    std::ranges::subrange sub{std::next(arr.begin(), 2), std::prev(arr.end(), 2)};
    std::println("1) sub: {}", sub);
    std::println("2) sub: {}", sub.next());
    std::println("3) sub: {}", sub.next(2));
}

输出

1) sub: [3, 4, 5]
2) sub: [4, 5]
3) sub: [5]

[edit] 参见

获取 subrange 的副本,其迭代器按给定距离递减
(public member function) [edit]
按给定距离递增迭代器
(public member function) [edit]
(C++11)
递增迭代器
(function template) [edit]
按给定距离或到边界递增迭代器
(algorithm function object)[edit]