std::span::...span::crend(3)
π std::span::rend, std::span::crend β C++ Standard Libary
okay bestie, welcome to the std::span::...span::crend(3) page from the C++ Standard Libary. this is the reverse-iterator end-boss squad, and it is lowkey iconic. π
πΈ NAME πΈ
std::span::rend,std::span::crend β std::span::rend,std::span::crend
β¨ Synopsis β¨
constexpr reverse_iterator rend() const noexcept; (1) (since C++20)
constexpr const_reverse_iterator crend() const noexcept; (2) (since C++23)
So here's the vibe: these functions return 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. That element is literally just a placeholder, and attempting to access it results in undefined behavior. not cute, bestie. π
The original docs also drop a diagram called range-rbegin-rend.svg, which is very demure, very cppreference. π¦
π Parameters π
(none)
π Return value π
Reverse iterator to the element following the last element. periodt. β¨
β Complexity β
Constant.
π§ Example π§
// Run this code
#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:
β β β β β
β β β β β β β
β β β β
π See also π
rbeginβ returns a reverse iterator to the beginningcrbeginβ(public member function)(C++23)rendβ returns a reverse end iterator for a container or arraycrendβ(function template)(C++14)
mwah π that's the whole page. source: http://cppreference.com, version/date: 2024.06.10, manual page: std::span::...span::crend(3). stay safe, and remember: that placeholder is for looking, not touching β undefined behavior is not the moment. ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms