std::ranges::adjacent_view<V,N>:: adjacent_view
From cppreference.net
<
cpp
|
ranges
|
adjacent view
C++
Ranges library
|
||||||||||||||||||||||
| Range primitives | |||||||
|
|||||||
| Range concepts | |||||||||||||||||||
|
|||||||||||||||||||
| Range factories | |||||||||
|
|||||||||
| Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||
| Helper items | |||||||||||||||||
|
|
||||||||||||||||
std::ranges::adjacent_view
| Member functions | ||||
|
adjacent_view::adjacent_view
|
||||
|
(C++26)
|
||||
| Iterator | ||||
| Member functions | ||||
| Non-member functions | ||||
| Sentinel | ||||
| Member functions | ||||
| Non-member functions | ||||
|
adjacent_view
(
)
requires
std::
default_initializable
<
V
>
=
default
;
|
(1) | (depuis C++23) |
|
constexpr
explicit
adjacent_view
(
V base
)
;
|
(2) | (depuis C++23) |
Construit une
adjacent_view
.
1)
Constructeur par défaut.
Initialise par valeur
la vue sous-jacente.
Paramètres
| base | - | la vue sous-jacente |
Exemple
Exécuter ce 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); // surcharge (2) for (auto const& tuple : view) print(tuple); }
Sortie :
v: ABCDEF ABCD BCDE CDEF