std::ranges...djacent_view(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

okay so you opened the std::ranges...djacent_view(3) page in the C++ Standard Library manual, and the NAME up top is literally std::ranges::adjacent_view::adjacent_view - std::ranges::adjacent_view::adjacent_view β€” yep, constructor name twice, it's giving main-character duplication πŸ’…. This page is all about the adjacent_view constructor, no cap.

✨ Synopsis ✨

Both constructors are since C++23, bestie. Here's the exact synopsis, untouched:

          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 β€” yes, that's the whole sentence πŸ’–.

  1. Default constructor. Value-initializes the underlying view. ✨
  2. Initializes the underlying view base_ with std::move(base). πŸ”₯

🌸 Parameters 🌸

  • base β€” the underlying view 🫢

πŸŽ€ Example πŸŽ€

This is the whole example, copied exactly so you can run it:

// 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

okay that's the whole page, bestie! 🫢 Cute sign-off with the footer info: source/version http://cppreference.com, date 2024.06.10, and page tag std::ranges...djacent_view(3). Mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from