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

履歴 編集

function
<ranges>

std::ranges::take_view::end(C++20)

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

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

概要

番兵を取得する。

戻り値

入力がsized_rangeかつrandom_access_rangeの場合:

それ以外の場合:

  • (1), (2) : 以下と等価:
    return counted_iterator{ranges::begin(base_), count_};
    

ただし、base_は元のviewを表すメンバ変数、count_は取得する要素数を表すメンバ変数。

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

int main() {
  std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

  std::ranges::take_view r{vec, 5};

  auto it = r.begin();
  auto end_it = r.end();
  while (it != end_it) {
    int x = *it;
    std::cout << x << " ";
    ++it;
  }
  std::cout << std::endl;
}

出力

1 2 3 4 5 

バージョン

言語

  • C++20

処理系