std::flat_set::rend,(3)
π NAME
std::flat_set::rend β okay so this is literally the rend of std::flat_set, bestie. It's the reverse-end iterator situation, and yes it's giving "the end but backwards" β¨
Also hi, this page lives in the C++ Standard Library section of the manual (that's the manual name, folding it in near the top like you asked π«Ά).
π Synopsis
reverse_iterator rend() noexcept; (1) (since C++23)
const_reverse_iterator rend() const noexcept; (2) (since C++23)
const_reverse_iterator crend() const noexcept; (3) (since C++23)
So what does it actually do? It returns a reverse iterator pointing to the element following the last element of the reversed flat_set. Which sounds like nonsense until you remember reverse iterators are little gremlins: it corresponds to the element preceding the first element of the non-reversed flat_set (deranged, iconic, no notes π
).
That element is just a placeholder β it's not a real thing you can look at. Attempting to access it results in undefined behavior π so likeβ¦ don't.
range-rbegin-rend.svg β yeah that's the little diagram that ships with this page, love that for us π¦
πΈ Parameters
(none) β zero, nada, zip. She takes no arguments and she's thriving π
β¨ Return value
A reverse iterator to the element following the last element. That's it, that's the whole return value π
β Complexity
Constant. O(1), instant, no cap π₯
π Notes
Okay important detail, bestie: both iterator and const_iterator are constant iterators here (and they may in fact be the same type, which is a whole vibe). So it is not possible to mutate the elements of the container through an iterator returned by any of these member functions. No sneaky writes. Not today. π
π Example
// Run this code
#include <iostream>
#include <flat_set>
int main()
{
std::flat_set<unsigned> rep{1, 2, 3, 4, 1, 2, 3, 4};
for (auto it = rep.crbegin(); it != rep.crend(); ++it)
{
for (auto n = *it; n > 0; --n)
std::cout << "βΌ" << ' ';
std::cout << '\n';
}
}
π Output
βΌ βΌ βΌ βΌ
βΌ βΌ βΌ
βΌ βΌ
βΌ
Look at that little staircase, we ate π§
π See also
rbeginβ returns a reverse iterator to the beginning (public member function)crbeginβ returns a reverse iterator to the beginning (public member function)rendβ returns a reverse end iterator for a container or array (function template)crendβ returns a reverse end iterator for a container or array (function template) (C++14)
fr fr that's the whole page β go forth and iterate backwards responsibly π
Source/version and date, cute sign-off style: this one came from http://cppreference.com, dated 2024.06.10, and the page itself is std::flat_set::rend,(3). Periodt. π
β¨
π¦ 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