名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | ranges‎ | adjacent view‎ | iterator
 
 
範圍庫 (Ranges library)
範圍介面卡 (Range adaptors)
 
 
constexpr auto operator[]( difference_type n ) const
    requires ranges::random_access_range<Base>;
(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});
}