std::map::r...ap::crbegin(3)

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

🌟 NAME 🌟

Welcome to the C++ Standard Libary page for std::map::r...ap::crbegin(3) β€” yes, β€œLibary” is spelled exactly like that in the manual name, and we are not fixing it, periodt. πŸ’…

std::map::rbegin,std::map::crbegin - std::map::rbegin,std::map::crbegin

That’s the name, bestie. No cap.


πŸ¦‹ Synopsis πŸ¦‹

Here are the signatures, looking iconic:

reverse_iterator rbegin();                       (1) (noexcept since C++11)
const_reverse_iterator rbegin() const;           (2) (noexcept since C++11)
const_reverse_iterator crbegin() const noexcept; (3) (since C++11)

Okay so this returns a reverse iterator to the first element of the reversed map. It corresponds to the last element of the non-reversed map. If the map is empty, the returned iterator is equal to rend() β€” empty-map behavior, iykyk.

There’s a lil diagram named range-rbegin-rend.svg in the original page β€” visual support, slay. πŸ¦‹

🌸 Parameters 🌸

(none) β€” literally no parameters. Zero. Zilch. She takes nothing and still serves. πŸ’…

✨ Return value ✨

Reverse iterator to the first element. That’s the whole return value, no extra lore. πŸŽ€

⭐ Complexity ⭐

Constant. That’s it. Iconic and constant. ⭐

🫢 Notes 🫢

Invalidation tea: 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 like, if the end iterator gets invalidated, your returned reverse iterator gets invalidated too β€” important vibe check, no cap. 😭

Also, libc++ backports crbegin() to C++98 mode. Cute. Time travel behavior, iykyk. πŸ•°οΈβœ¨

πŸ’» Example πŸ’»

Run this code, bestie:

// Run this code

#include <iomanip>
#include <iostream>
#include <string_view>
#include <map>

int main()
{
    const std::map<int, std::string_view> coins
    {
        {10, "dime"},
        {100, "dollar"},
        {50, "half dollar"},
        {5, "nickel"},
        {1, "penny"},
        {25, "quarter"}
    }; // initializer entries in name alphabetical order

    std::cout << "US coins in circulation, largest to smallest denomination:\n";
    for (auto it = coins.crbegin(); it != coins.crend(); ++it)
        std::cout << std::setw(11) << it->second << " = Β’" << it->first << '\n';
}

🌈 Output 🌈

US coins in circulation, largest to smallest denomination:
     dollar = Β’100
half dollar = Β’50
    quarter = Β’25
       dime = Β’10
     nickel = Β’5
      penny = Β’1

πŸ‘€ See also πŸ‘€

  • rend β€” returns a reverse iterator to the end
  • crend β€” (public member function) (C++11)
  • rbegin β€” returns a reverse iterator to the beginning of a container or array
  • crbegin β€” (function template) (C++14)

That’s the page, bestie! Source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::map::r...ap::crbegin(3). Byeeee, go reverse-iterate something iconic. πŸ’–πŸŽ€βœ¨πŸŒˆ

πŸ“¦ where this page comes from