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