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});
}