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);
ここで、iterator
はenumerate_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
処理系
- Clang: 17 ✅
- GCC: 13 ✅
- Visual C++: 2022 Update 7 ✅