Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.45 KB

File metadata and controls

68 lines (51 loc) · 1.45 KB

begin

  • ranges[meta header]
  • std::ranges[meta namespace]
  • enumerate_view[meta class]
  • function[meta id-type]
  • cpp23[meta cpp]
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;
}
  • begin[color ff0000]

出力

0: a
1: b

バージョン

言語

  • C++23

処理系

  • Clang: 17 [mark verified]
  • GCC: 13 [mark verified]
  • Visual C++: 2022 Update 7 [mark verified]

参照