# std::ranges::chunk_by_view<V,Pred>::begin

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

Returns an iterator to the first element of the chunk_by_view.

## Official Specification Summary (cppreference)

```cpp
constexpr /*iterator*/ begin(); // (since C++23)
```

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

Equivalent to:

```cpp
ranges::iterator_t<V> iter;

if (begin_.has_value())
    iter = begin_.value();
else
{
    iter = /*find_next*/(ranges::begin(base()));
    begin_ = iter; // caching
}

return /*iterator*/(*this, ranges::begin(base()), iter);
```

The behavior is undefined if the underlying predicate `pred_` does not contain a value.

### Parameters

(none)

### Return value

Iterator to the first element.

### Notes

In order to provide the amortized constant-time complexity required by the `range` concept, this function caches the result within the data member `begin_` for use on subsequent calls.

### Example

> Note: This section is incomplete Reason: no example

### See also

- [`end`](https://en.cppreference.com/w/cpp/ranges/chunk_by_view/end): returns an iterator or a sentinel to the end (public member function)
- [`ranges::begin`](https://en.cppreference.com/w/cpp/ranges/begin) (C++20): returns an iterator to the beginning of a range (customization point object)

---
Attribution: content from https://en.cppreference.com/w/cpp/ranges/chunk_by_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.