constexpr auto begin(); // (1) C++23
constexpr auto begin() const
requires range<const InnerView> &&
regular_invocable<const F&, REPEAT(range_reference_t<const V>, N)...>; // (2) C++23
概要
先頭を指すイテレータを取得する。
効果
- (1) :
return iterator<false>(*this, inner_.begin()); - (2) :
return iterator<true>(*this, inner_.begin());
ここで、iteratorはadjacent_transform_viewの内部で定義される説明専用のイテレータクラスであり、InnerViewは説明専用のadjacent_view<V, N>である。
備考
REPEAT(T, N)をT型のN個のパックとする。
例
#include <ranges>
#include <vector>
#include <iostream>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5};
auto diff = [](int x, int y) { return y - x; };
std::ranges::adjacent_transform_view<std::views::all_t<std::vector<int>&>, decltype(diff), 2> atv(v, diff);
auto it = atv.begin();
// 最初の要素(隣接する2要素の差)
std::cout << *it << std::endl; // 2 - 1 = 1
// 次の要素へ
++it;
std::cout << *it << std::endl; // 3 - 2 = 1
}
出力
1
1
バージョン
言語
- C++23
処理系
- Clang: 20 ❌
- GCC: 15 ❌
- Visual C++: 2022 Update 14 ❌