# std::ranges::slide_view<V>::begin

> C++ Atlas: `cppatlas.com/w/cpp/ranges/slide_view/begin` | Source: https://en.cppreference.com/w/cpp/ranges/slide_view/begin | Domain: Ranges | Standards: C++23

Returns an iterator to the first element of the slide_view.

## Official Specification Summary (cppreference)

```cpp
constexpr auto begin()
    requires (!(/*simple-view*/<V> && /*slide-caches-nothing*/<const V>)); // (1) (since C++23)

constexpr auto begin() const
    requires /*slide-caches-nothing*/<const V>; // (2) (since C++23)
```

Returns an iterator to the first element of the `slide_view`.

1) If `V` models `slide-caches-first`, equivalent to:

   `return iterator<false>(ranges::begin(base_), ranges::next(ranges::begin(base_), n_ - 1, ranges::end(base_)), n_);`

   Otherwise, equivalent to: `return iterator<false>(ranges::begin(base_), n_);`.

If `V` models `slide-caches-first` this function caches the result within the `cached_begin_` for use on subsequent calls. This is necessary to provide the amortized constant-time complexity required by the `range`.

2) Equivalent to: `return iterator<true>(ranges::begin(base_), n_);`.

### Parameters

(none)

### Return value

An iterator to the first element of `slide_view`, which points to the `n_`-sized subrange of the possibly const-qualified underlying view type – `V` for overload (1) or `const V` for overload (2).

### Example

```cpp
#include <iostream>
#include <ranges>
#include <string_view>
using namespace std::literals;

int main()
{
    static constexpr auto source = {"∀x"sv, "∃y"sv, "ε"sv, "δ"sv};
    auto view{std::ranges::slide_view(source, 2)};
    const auto subrange{*(view.begin())};
    for (std::string_view const s : subrange)
        std::cout << s << ' ';
    std::cout << '\n';
}
```

Output:

```text
∀x ∃y
```

### See also

- [`end`](https://en.cppreference.com/w/cpp/ranges/slide_view/end): returns an iterator or a sentinel to the end (public member function)
- [`operator==`](https://en.cppreference.com/w/cpp/ranges/slide_view/sentinel/operator_cmp) (C++23): compares a sentinel with an iterator returned from `slide_view::begin` (function)

---
Attribution: content from https://en.cppreference.com/w/cpp/ranges/slide_view/begin (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.