std::span<T,Extent>::rend, std::span<T,Extent>::crend
constexpr reverse_iterator rend() const noexcept; | (1) | (since C++20) |
constexpr const_reverse_iterator crend() const noexcept; | (2) | (since C++23) |
Возвращает обратный итератор к элементу, следующему за последним элементом перевернутого span. Он соответствует элементу, предшествующему первому элементу исходного span. Этот элемент является плейсхолдером, попытка доступа к нему приводит к неопределённому поведению.
Параметры
(нет)
Значение возврата
Обратный итератор к элементу, следующему за последним элементом.
Сложность
Постоянная.
Пример
#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");
}Вывод:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
См. также
|
(C++23) | возвращает обратный итератор к началу (public member function) |
|
(C++14) | возвращает обратный итератор к концу контейнера или массива (шаблон функции) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/span/rend