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

履歴 編集

function
<ranges>

std::ranges::enumerate_view::begin(C++23)

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

constexpr auto begin() const
  requires range-with-movable-references<const V>; // (2) C++23

概要

先頭を指すイテレータを取得する。

効果

  • (1) : return iterator<false>(ranges::begin(base_), 0);
  • (2) : return iterator<true>(ranges::begin(base_), 0);

ここで、iteratorenumerate_viewの内部で定義される説明専用のイテレータクラスである。

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

int main() {
  std::vector<char> v = {'a', 'b', 'c'};

  std::ranges::enumerate_view ev(v);

  auto it = ev.begin();

  // 最初の要素(インデックスと値のタプル)
  auto [index, value] = *it;
  std::cout << index << ": " << value << std::endl;

  // 次の要素へ
  ++it;
  auto [index2, value2] = *it;
  std::cout << index2 << ": " << value2 << std::endl;
}

出力

0: a
1: b

バージョン

言語

  • C++23

処理系

参照