constexpr reverse_iterator rend() const noexcept; | (since C++20) |
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.
(none).
Reverse iterator to the element following the last element.
Constant.
#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:
▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁
(C++20) | returns a reverse iterator to the beginning (public member function) |
(C++14) | returns a reverse end iterator for a container or array (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/span/rend