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

履歴 編集

function
<ranges>

std::ranges::adjacent_view::end(C++23)

constexpr auto end()
  requires (!simple-view<V>);                              // (1) C++23

constexpr auto end() const
  requires range<const V>;                                 // (2) C++23

概要

番兵を取得する。

効果

common_range<V>trueの場合:

  • (1) : return iterator<false>(as-sentinel{ranges::end(base_)}, ranges::begin(base_), ranges::end(base_));
  • (2) : return iterator<true>(as-sentinel{ranges::end(base_)}, ranges::begin(base_), ranges::end(base_));

それ以外の場合:

  • (1) : return sentinel<false>(ranges::end(base_));
  • (2) : return sentinel<true>(ranges::end(base_));

ここで、iteratorsentineladjacent_viewの内部で定義される説明専用のクラスであり、as-sentinelは説明専用の空クラスである。

#include <ranges>
#include <vector>
#include <iostream>

int main() {
  std::vector<int> v = {1, 2, 3, 4, 5};

  std::ranges::adjacent_view<std::views::all_t<std::vector<int>&>, 3> av(v);

  auto begin = av.begin();
  auto end = av.end();

  // 全要素を出力
  for (auto it = begin; it != end; ++it) {
    auto [a, b, c] = *it;
    std::cout << a << ", " << b << ", " << c << std::endl;
  }
}

出力

1, 2, 3
2, 3, 4
3, 4, 5

バージョン

言語

  • C++23

処理系

参照