Namespaces
Variants

std::array<T,N>::rbegin, std::array<T,N>::crbegin

De fr.cppreference.net

 
 
 
 
reverse_iterator rbegin() noexcept;
(1) (depuis C++11)
(constexpr depuis C++17)
const_reverse_iterator rbegin() const noexcept;
(2) (depuis C++11)
(constexpr depuis C++17)
const_reverse_iterator crbegin() const noexcept;
(3) (depuis C++11)
(constexpr depuis C++17)

Retourne un itérateur inverse vers le premier élément du array. Il correspond au dernier élément du array. Si le array est vide, l'itérateur retourné est égal à rend().

Valeur de retour

Itérateur inverse vers le premier élément.

Complexité

Constante.

Notes

L' itérateur sous-jacent de l'itérateur inverse retourné est l' itérateur de fin . Par conséquent, l'itérateur retourné est invalidé si et quand l'itérateur de fin est invalidé.

Exemple

#include <algorithm>
#include <iostream>
#include <string>
#include <string_view>
#include <array>

void print(const std::string_view s) { std::cout << s << ' '; }

int main()
{
    const std::array<std::string_view, 8> data
    {
        "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"
    };
    std::array<std::string, 8> arr;

    std::copy(data.cbegin(), data.cend(), arr.begin());

    print("Print 'arr' in direct order using [cbegin, cend):\t");
    std::for_each(arr.cbegin(), arr.cend(), print);

    print("\n\nPrint 'arr' in reverse order using [crbegin, crend):\t");
    std::for_each(arr.crbegin(), arr.crend(), print);
}

Sortie :

Print 'arr' in direct order using [cbegin, cend):        ▁ ▂ ▃ ▄ ▅ ▆ ▇ █

Print 'arr' in reverse order using [crbegin, crend):     █ ▇ ▆ ▅ ▄ ▃ ▂ ▁

Voir aussi

retourne un itérateur inverse vers la fin
(fonction membre publique)
retourne un itérateur inverse vers le début d'un conteneur ou d'un tableau
(fonction template)