Namespaces
Variants

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

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

지정된 상대 위치의 요소를 반환합니다.

current_를 기본 반복자 배열이라고 하자.

다음과 동일합니다:

return /*tuple-transform*/([&](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});
}