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