最終更新日時(UTC):
が更新

履歴 編集

function
<ranges>

std::ranges::subrange::next(C++20)

[[nodiscard]]
constexpr subrange
  next(iter_difference_t<I> n = 1) const &
    requires forward_iterator<I>;            // (1) C++20
constexpr subrange
  next(iter_difference_t<I> n = 1) const &
    requires forward_iterator<I>;            // (1) C++26

[[nodiscard]]
constexpr subrange
  next(iter_difference_t<I> n = 1) &&;       // (2) C++20
constexpr subrange
  next(iter_difference_t<I> n = 1) &&;       // (2) C++26

概要

先頭を前進させたsubrangeを得る。

効果

(1)

auto tmp = *this;
tmp.advance(n);
return tmp;

(2)

advance(n);
return std::move(*this);

#include <ranges>
#include <iostream>

template<std::ranges::range R>
void print(const R& r) {
  for (int x : r) {
    std::cout << x << ',';
  }
  std::cout << '\n';
}

int main()
{
  constexpr int a[] = {1, 2, 3, 4, 5};
  std::ranges::subrange sub(a + 1, a + 4);

  print(sub);
  print(sub.next());
  print(sub.next().next());
}

出力

2,3,4,
3,4,
4,

バージョン

言語

  • C++20

処理系

参照