std::array<T,N>::rend, std::array<T,N>::crend
iterator rend() noexcept; |
(1) | (с C++11) (constexpr с C++17) |
const_iterator rend() const noexcept; |
(2) | (с C++11) (constexpr с C++17) |
const_iterator crend() const noexcept; |
(3) | (с C++11) (constexpr с C++17) |
Возвращает обратный итератор на элемент, следующий за последним элементом обращённого array. Он соответствует элементу, предшествующему первому элементу необращённого array. Этот элемент используется как плейсхолдер, попытка доступа к нему приводит к неопределённому поведению.
Параметры
(нет)
Возвращаемое значение
Обратный итератор на элемент, следующий за последним элементом.
Сложность
Постоянная.
Пример
#include <algorithm>
#include <array>
#include <iostream>
int main()
{
std::array<int, 11> a{1, 11, 11, 35, 0, 12, 79, 76, 76, 69, 40};
// print elements of array in reverse order using const_reverse_iterator`s
std::for_each(a.crbegin(), a.crend(), [](int e){ std::cout << e << ' '; });
// ^^ ^^
std::cout << '\n';
// modify each element of array using non-const reverse_iterator`s
std::for_each(a.rbegin(), a.rend(), [](int& e){ e += 32; });
// ^ ^ ^
// print elements as chars in reverse order using const_reverse_iterator`s
std::for_each(a.crbegin(), a.crend(), [](char e){ std::cout << e; });
// ^^ ^^ ^^^^
std::cout << '\n';
}Вывод:
40 69 76 76 79 12 0 35 11 11 1 Hello, C++!
См. также
| возвращает обратный итератор к началу (общедоступный член-функция) |
|
|
(C++14) |
возвращает обратный конечный итератор для контейнера или массива (шаблон функции) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/array/rend