std::ranges::adjacent_view<V,N>::adjacent_view
From cppreference.com
< cpp | ranges | adjacent view
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++26)(C++26)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
std::ranges::adjacent_view
adjacent_view::adjacent_view
(C++26)
Member functions
Non-member functions
adjacent_view() requires std::default_initializable <V> = default;
(1)
(since C++23)
constexpr explicit adjacent_view( V base );
(2)
(since C++23)
Constructs an adjacent_view
.
1) Default constructor. Value-initializes the underlying view.
[edit] Parameters
base
-
the underlying view
[edit] Example
Run this code
#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); }
Output:
v: ABCDEF ABCD BCDE CDEF