# std::span<T,Extent>::rend, std::span<T,Extent>::crend

> C++ Atlas: `cppatlas.com/w/cpp/container/span/rend` | Source: https://en.cppreference.com/w/cpp/container/span/rend | Domain: Containers | Standards: C++14, C++20, C++23

Returns a reverse iterator to the element following the last element of the reversed span. It corresponds to the element preceding the first element of the non-reversed span.

## Official Specification Summary (cppreference)

```cpp
constexpr reverse_iterator rend() const noexcept; // (1) (since C++20)
constexpr const_reverse_iterator crend() const noexcept; // (2) (since C++23)
```

Returns a reverse iterator to the element following the last element of the reversed `span`. It corresponds to the element preceding the first element of the non-reversed `span`. This element acts as a placeholder, attempting to access it results in undefined behavior.

### Parameters

(none)

### Return value

Reverse iterator to the element following the last element.

### Complexity

Constant.

### Example

```cpp
#include <algorithm>
#include <iostream>
#include <span>
#include <string_view>

void ascending(const std::span<const std::string_view> data,
               const std::string_view term)
{
    std::for_each(data.begin(), data.end(),
        [](const std::string_view x) { std::cout << x << ' '; });
    std::cout << term;
}

void descending(const std::span<const std::string_view> data,
                const std::string_view term)
{
    std::for_each(data.rbegin(), data.rend(),
        [](const std::string_view x) { std::cout << x << ' '; });
    std::cout << term;
}

int main()
{
    constexpr std::string_view bars[]{"▁","▂","▃","▄","▅","▆","▇","█"};
    ascending(bars, " ");
    descending(bars, "\n");
}
```

Output:

```text
▁ ▂ ▃ ▄ ▅ ▆ ▇ █  █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
```

### See also

- [`rbegin`](https://en.cppreference.com/w/cpp/container/span/rbegin), [`crbegin`](https://en.cppreference.com/w/cpp/container/span/rbegin) (C++23): returns a reverse iterator to the beginning (public member function)
- [`rend`](https://en.cppreference.com/w/cpp/iterator/rend) (C++14), [`crend`](https://en.cppreference.com/w/cpp/iterator/rend): returns a reverse end iterator for a container or array (function template)

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