std::ranges::adjacent_view<V,N>::iterator<Const>::operator[]
来自 cppreference.cn
< cpp | ranges | adjacent view | iterator
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}); }