最終更新日時:
が更新

履歴 編集

function
<ranges>

std::ranges::concat_view::end(C++26)

constexpr auto end()
  requires (!simple-view<Views> || ...);       // (1) C++26

constexpr auto end() const
  requires (range<const Views> && ...);        // (2) C++26

概要

終端イテレータもしくは番兵を取得する。

効果

is-constを、const修飾版の (2) ではtrue、非const版の (1) ではfalseとする。Viewsの要素数をNとして、以下と等価である:

  • 全ての範囲(is-constに応じてconst修飾したもの)がforward_rangeであり、かつ最後の範囲Views...[N - 1]common_rangeである場合、最後の範囲の終端を指すconcat_viewのイテレータを返す。
  • そうでなければ、default_sentinelを返す。

#include <print>
#include <ranges>
#include <array>
#include <vector>

int main() {
  std::vector<int> v1{1, 2, 3};
  std::vector<int> v2{4, 5};
  std::array<int, 3> a{6, 7, 8};

  std::ranges::concat_view r{v1, v2, a};

  auto it = r.begin();
  auto end_it = r.end();
  while (it != end_it) {
    std::print("{} ", *it);
    ++it;
  }
  std::println();
}

出力

1 2 3 4 5 6 7 8

バージョン

言語

  • C++26

処理系

参照