std::flat_m...set::rbegin,(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ 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 end
  • crend β€” (public member function)
  • rbegin β€” returns a reverse iterator to the beginning of a container or array
  • crbegin β€” (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