Namespaces
Variants

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

From cppreference.net

constexpr reverse_iterator rend ( ) const noexcept ;
(1) (desde C++20)
constexpr const_reverse_iterator crend ( ) const noexcept ;
(2) (desde C++23)

Devuelve un iterador inverso más allá del último elemento del * this invertido. Corresponde al elemento que precede al primer elemento del * this no invertido.

Este iterador devuelto solo actúa como centinela. No se garantiza que sea dereferenceable .

range-rbegin-rend.svg

Contenidos

Valor de retorno

Iterador inverso al elemento siguiente al último elemento.

Complejidad

Constante.

Ejemplo

#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");
}

Salida:

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

Véase también

devuelve un iterador inverso al principio
(función miembro pública)
(C++14)
devuelve un iterador inverso final para un contenedor o array
(plantilla de función)