std::ranges::slide_view<V>::slide_view
来自cppreference.com
< cpp | ranges | slide view
constexpr explicit slide_view( V base, ranges::range_difference_t<V> n ); |
(C++23 起) | |
构造 slide_view
并初始化底层数据成员:
参数
base | - | 源视图 |
n | - | “滑窗”的大小 |
示例
运行此代码
#include <algorithm> #include <iostream> #include <ranges> int main() { const auto source = {1, 2, 3, 4}; auto slide = std::views::slide(source, 3); std::ranges::for_each(slide, [](std::ranges::viewable_range auto&& w) { std::cout << '[' << w[0] << ' ' << w[1] << ' ' << w[2] << "]\n"; }); }
输出:
[1 2 3] [2 3 4]