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

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

πŸ’… std::flat_multimap::rbegin β€” C++ Standard Library, but make it cute πŸ’…

okay so bestie, this is the std::flat_multimap::rbegin page from the C++ Standard Library β€” the header line is out here serving std::flat_m...map::rbegin,(3), and the original is spelling it C++ Standard Libary (typo included, periodt). We're gonna cover every single thing so you can reverse-iterate with main character energy. 🫢✨

🌸 NAME 🌸

  • std::flat_multimap::rbegin, β€” std::flat_multimap::rbegin,
the commas in the NAME line are not a typo I made, they're canon. respect the commas. πŸ’…

πŸ¦‹ 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)

okay so overload (1) is the regular rbegin(), overload (2) is the const rbegin(), and overload (3) is crbegin(), also const. all three are noexcept, and all three are since C++23. slay. ✨

So what does it do? It returns a reverse iterator to the first element of the reversed flat_multimap. That corresponds to the last element of the non-reversed flat_multimap. If the flat_multimap is empty, the returned iterator is equal to rend(). there's also a diagram in the original labeled range-rbegin-rend.svg doing its little visual thing. πŸ¦‹

🌟 Parameters 🌟

none. literally none. (none). we love a low-maintenance function. πŸ’…

πŸ‘‘ Return value πŸ‘‘

a reverse iterator to the first element. that's it, that's the tea. πŸ‘‘

πŸ”₯ Complexity πŸ”₯

Constant. ⚑

🧚 Notes 🧚

okay this part is important, bestie: the underlying iterator of the returned reverse iterator is the end iterator. so the returned iterator is invalidated if and when the end iterator is invalidated. not me warning you about invalidation, but yes, that's the vibe check. 😭

🌈 Example 🌈

// Run this code

        #include <algorithm>
        #include <iostream>
        #include <string>
        #include <flat_map>

        int main()
        {
            std::flat_multimap<std::string, int> map
            {
                {"β–ˆ", 1},
                {"β–’", 5},
                {"β–‘", 3},
                {"β–“", 7},
                {"β–“", 8},
                {"β–‘", 4},
                {"β–’", 6},
                {"β–ˆ", 2}
            };

            std::cout << "Print out in reverse order using const reverse
       iterators:\n";
            std::for_each(map.crbegin(), map.crend(),
                [](std::pair<const std::string, int> const& e)
                {
                    std::cout << "{ \"" << e.first << "\", " << e.second << "
       };\n";
                });

            map.rbegin()->second = 42; // OK: non-const value is modifiable
        //  map.crbegin()->second = 42; // Error: cannot modify the const value
        }

πŸ’– Possible output πŸ’–

        Print out in reverse order using const reverse iterators:
        { "β–“", 8 };
        { "β–“", 7 };
        { "β–’", 6 };
        { "β–’", 5 };
        { "β–‘", 4 };
        { "β–‘", 3 };
        { "β–ˆ", 2 };
        { "β–ˆ", 1 };

🌸 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)

okay that's the whole page, bestie 🫢 source/version + date sign-off: http://cppreference.com, 2024.06.10, and the page name is std::flat_m...map::rbegin,(3). now go reverse-iterate something iconic. πŸ’…βœ¨

πŸ“¦ where this page comes from