std::ranges::drop_while_view<V,Pred>::base

From cppreference.com
 
 
 
 
constexpr V base() const& requires std::copy_constructible<V>;
(1) (since C++20)
constexpr V base() &&;
(2) (since C++20)

Returns a copy of the underlying view.

1) Copy constructs the result from the underlying view.
2) Move constructs the result from the underlying view.

Parameters

(none)

Return value

A copy of the underlying view.

Example

#include <array>
#include <ranges>
#include <iostream>
 
void print(auto const& container) {
    for (const auto& elem : container)
        std::cout << elem << ' ';
    std::cout << '\n';
}
 
int main()
{
    std::array data{ 1, 2, 3, 4 };
    print(data);
 
    auto stub = [](int x) { return x < 2; };
    auto view = std::ranges::drop_while_view{ data, stub };
 
    auto base = view.base(); // `base` refers to the `data`
 
    std::ranges::reverse(base); //< changes `data` indirectly
    print(data);
}

Output:

1 2 3 4 
4 3 2 1