constexpr auto end()
requires (!simple-view<Views> || ...); // (1) C++26
constexpr auto end() const
requires (range<const Views> && ...); // (2) C++26
概要
終端イテレータもしくは番兵を取得する。
効果
is-constを、const修飾版の (2) ではtrue、非const版の (1) ではfalseとする。Viewsの要素数をNとして、以下と等価である:
- 全ての範囲(
is-constに応じてconst修飾したもの)がforward_rangeであり、かつ最後の範囲Views...[N - 1]がcommon_rangeである場合、最後の範囲の終端を指すconcat_viewのイテレータを返す。 - そうでなければ、
default_sentinelを返す。
例
#include <print>
#include <ranges>
#include <array>
#include <vector>
int main() {
std::vector<int> v1{1, 2, 3};
std::vector<int> v2{4, 5};
std::array<int, 3> a{6, 7, 8};
std::ranges::concat_view r{v1, v2, a};
auto it = r.begin();
auto end_it = r.end();
while (it != end_it) {
std::print("{} ", *it);
++it;
}
std::println();
}
出力
1 2 3 4 5 6 7 8
バージョン
言語
- C++26
処理系
- Clang: 23 ✅
- GCC: 15 ✅
- Visual C++: 2022 Update 14 ❌
参照
- LWG Issue 4166.
concat_view::end()should be more constrained in order to support noncopyable iterators- C++26で、
end()の効果で終端イテレータを返す条件に「全ての範囲がforward_rangeであること」(all-forward)が追加された。一部の範囲が前方範囲でない場合にイテレータを返してしまい、コピー不可能なイテレータを含む場合などに問題が生じるのを防ぐもの
- C++26で、