std::flat_m...set::rbegin,(3)
β¨ NAME β¨
std::flat_multiset::rbegin β okay so this is the std::flat_multiset::rbegin, situation (yes the man page name has a lil trailing comma, we don't question it π
) β it's the vibe where you get a reverse iterator pointing at the first element of the reversed container. Bestie, we're going backwards today π¦
πΈ Synopsis πΈ
reverse_iterator rbegin() noexcept; (1) (since C++23)
const_reverse_iterator rbegin() const noexcept; (2) (since C++23)
const_reverse_iterator crbegin() const noexcept; (3) (since C++23)
So like, it returns a reverse iterator to the first element of the reversed flat_multiset. And that first element of the reversed thing? Yeah that's literally the last element of the non-reversed flat_multiset. Iconic mirror moment πͺ
And if the flat_multiset is empty, the iterator you get back is equal to rend(). No cap, that's the whole rule.
There's a diagram in the original, range-rbegin-rend.svg β picture the little arrows hugging the container from both ends, that's the energy π«Ά
π Parameters π
(none) β not a single argument, she takes nothing and still slays.
π Return value π
Reverse iterator to the first element. That's it, that's the whole gift π
β Complexity β
Constant. O(1). Fast fast. She does not take her time, she's already there π₯
π Notes π
Okay this part matters, listen up bestie:
Because both iterator and const_iterator are constant iterators (and may in fact be the same type), it is not possible to mutate the elements of the container through an iterator returned by any of these member functions. Like, no editing the elements through this iterator. None. The door is locked π
Also: the underlying iterator of the returned reverse iterator is the end iterator. Hence the returned iterator is invalidated if and when the end iterator is invalidated. So if the end iterator goes π, your reverse iterator goes π too. They're linked, iykyk.
π Example π
// Run this code
#include <iostream>
#include <flat_set>
int main()
{
std::flat_multiset<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 staircase. She's descending and she's gorgeous π β¨
π§ See also π§
rendβ returns a reverse iterator to the endcrendβ (public member function)rbeginβ returns a reverse iterator to the beginning of a container or arraycrbeginβ (function template) (C++14)
lowkey the whole point:rbegin= start of the backwards walk,rend= where the backwards walk stops. Don't mix them up bestie π
Okay that's the page!! Big kiss from the C++ Standard Library, sourced from http://cppreference.com, dated 2024.06.10, filed under std::flat_m...set::rbegin,(3). Go forth and iterate in reverse, you absolute main character ππ
π¦ 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