std::multimap::rbegin,(3)
π std::multimap::rbegin,(3)
okay bestie, welcome to this page from the C++ Standard Libary manual β yes, thatβs the manual name, and the title up there is std::multimap::rbegin,(3). This whole page is about the reverse-begin vibes of std::multimap. π«Ά
β¨ NAME β¨
std::multimap::rbegin, - std::multimap::rbegin,
no cap, that trailing comma is literally in the name and we are respecting it π
π§Ύ Synopsis
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 multimap. It corresponds to the last element of the non-reversed multimap. And if the multimap is empty, the returned iterator is equal to rend(). π
thereβs also a diagram situation: range-rbegin-rend.svg β thatβs the visual bestie for this exact range-rbegin-rend energy.
π«Ά Parameters
(none)
π Return value
Reverse iterator to the first element.
β‘ Complexity
Constant. periodt. β‘
π§ Notes
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.
Also, libc++ backports crbegin() to C++98 mode.
π Example
// Run this code
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
int main()
{
std::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 endcrendβ (public member function) (C++11)rbeginβ returns a reverse iterator to the beginning of a container or arraycrbeginβ (function template) (C++14)
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::multimap::rbegin,(3) β mwah, go reverse-iterate responsibly πβ¨
π¦ 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