Namespaces
Variants

std::ranges::adjacent_view<V,N>:: iterator <Const>:: operator[]

From cppreference.net
Ranges library
Range adaptors
constexpr auto operator [ ] ( difference_type n ) const
requires ranges:: random_access_range < Base > ;
(C++23以降)

指定された相対位置にある要素を返します。

current_ を基盤となるイテレータの配列とする。

次と同等:

return /*タプル変換*/([&](auto& i) -> decltype(auto) { return i[n]; }, current_);

パラメータ

n - 現在位置からの相対位置

戻り値

現在位置からの変位 n にある要素。

#include <ranges>
#include <tuple>
int main()
{
    constexpr static auto v = {0, 1, 2, 3, 4, 5};
    //                               └──┬──┘  
    //                                  └─────────────────┐
    constexpr auto view = v | std::views::adjacent<3>; // │
    //                 ┌───────────────────┬──────────────┘ 
    //                 │                ┌──┴──┐
    static_assert(view[2] == std::tuple{2, 3, 4});
}