# std::ranges::enumerate_view<V>::end

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

Returns an iterator or a sentinel that compares equal to the end iterator of the enumerate_view.

## Official Specification Summary (cppreference)

```cpp
constexpr auto end() requires (!__simple_view<V>); // (1) (since C++23)
constexpr auto end() const requires /*range-with-movable-references*/<const V>; // (2) (since C++23)
```

Returns an iterator or a sentinel that compares equal to the end iterator of the `enumerate_view`.

Let `base_` denote the underlying view.

1) Equivalent to:

   ```cpp
   if constexpr (ranges::forward_range<V> and
                 ranges::common_range<V>  and
                 ranges::sized_range<V>)
       return /*iterator*/<false>(ranges::end(base_), ranges::distance(base_));
   else
       return /*sentinel*/<false>(ranges::end(base_));
   ```

2) Equivalent to:

   ```cpp
   if constexpr (ranges::forward_range<const V> and
                 ranges::common_range<const V>  and
                 ranges::sized_range<const V>)
       return /*iterator*/<true>(ranges::end(base_), ranges::distance(base_));
   else
       return /*sentinel*/<true>(ranges::end(base_));
   ```

### Parameters

(none)

### Return value

An iterator or a sentinel representing the end of the `enumerate_view`, as described above.

### Example

> Note: This section is incomplete Reason: no example

### Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

| DR | Applied to | Behavior as published | Correct behavior |
| --- | --- | --- | --- |
| LWG 3919 | C++23 | `ranges::distance` may invoke UB for sized common non-forward underlying ranges | sentinel type is returned for such ranges |

### See also

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

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