constexpr auto begin()
requires (!simple-view<V>); // (1) C++20
constexpr auto begin() const
requires range<const V>; // (2) C++20
概要
先頭を指すイテレータを取得する。
効果
- (1) :
return iterator<false>(ranges::begin(base_));
- (2) :
return iterator<true>(ranges::begin(base_));
ここで、iterator
はelements_view
の内部で定義される説明専用のイテレータクラスである。
例
#include <ranges>
#include <map>
#include <string>
#include <iostream>
int main() {
std::map<int, std::string> m = {{1, "one"}, {2, "two"}, {3, "three"}};
// keys_viewを使用
std::ranges::keys_view kv(m);
auto it = kv.begin();
std::cout << *it << std::endl; // 1
++it;
std::cout << *it << std::endl; // 2
// values_viewを使用
std::ranges::values_view vv(m);
auto vit = vv.begin();
std::cout << *vit << std::endl; // one
}
出力
1
2
one
バージョン
言語
- C++20
処理系
- Clang: 13.0.0 ✅
- GCC: 10.1.0 ✅
- ICC: ?
- Visual C++: 2019 Update 10 ✅