std::ranges::adjacent_view<V,N>::adjacent_view
来自cppreference.com
< cpp | ranges | adjacent view
adjacent_view() requires std::default_initializable<V> = default; |
(1) | (C++23 起) |
constexpr explicit adjacent_view( V base ); |
(2) | (C++23 起) |
构造 adjacent_view
。
1) 默认构造。值初始化底层视图。
参数
base | - | 底层视图 |
示例
运行此代码
#include <iostream> #include <ranges> #include <string> #include <tuple> template<class... Ts> void print(std::tuple<Ts...> const& tuple) { std::apply([&](auto&& arg, auto&&... args) { std::cout << arg; ((std::cout << args), ...); }, tuple); std::cout << '\n'; } int main() { const std::string v{"ABCDEF"}; constexpr int window_size{4}; std::cout << "v: " << v << '\n'; auto view = std::views::adjacent<window_size>(v); // overload (2) for (auto const& tuple: view) print(tuple); }
输出:
v: ABCDEF ABCD BCDE CDEF