std::multimap::rend,(3)
β¨ std::multimap::rend π
okay bestie, so this is the std::multimap::rend page from the C++ Standard Library β and it's literally the reverse-end iterator of a multimap. iconic behavior, no cap.
πΈ SYNOPSIS πΈ
reverse_iterator rend(); (1) (noexcept since C++11)
const_reverse_iterator rend() const; (2) (noexcept since C++11)
const_reverse_iterator crend() const noexcept; (3) (since C++11)
So what is it giving? It returns a reverse iterator to the element following the last element of the reversed multimap. Think about it like the mirror-world version of your map β and this iterator corresponds to the element preceding the first element of the non-reversed multimap. π
Now the important part, bestie: this element acts as a placeholder. That means attempting to access it results in undefined behavior. fr fr, do not dereference it. It's giving "look but don't touch" energy. π
range-rbegin-rend.svg
π PARAMETERS π
none. (none.) you want a parameter? there isn't one. periodt. β¨
π¦ RETURN VALUE π¦
Reverse iterator to the element following the last element. That's it, that's the whole vibe. π«Ά
β COMPLEXITY β
Constant. lowkey the easiest thing ever. π
π NOTES π
libc++ backports crend() to C++98 mode. cute of them, honestly. πΈ
π EXAMPLE π
// Run this code
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string_view>
#include <map>
using namespace std::chrono;
int main()
{
const std::multimap<year_month_day, int> messages
{
{February/17/2023, 10},
{February/17/2023, 20},
{February/16/2022, 30},
{October/22/2022, 40},
{June/14/2022, 50},
{November/23/2021, 60},
{December/10/2022, 55},
{December/12/2021, 45},
{April/1/2020, 42},
{April/1/2020, 24}
};
std::cout << "Messages received (date order is reversed):\n";
for (auto it = messages.crbegin(); it != messages.crend(); ++it)
std::cout << it->first << " : " << it->second << '\n';
}
π Possible output π
Messages received (date order is reversed):
2023-02-17 : 20
2023-02-17 : 10
2022-12-10 : 55
2022-10-22 : 40
2022-06-14 : 50
2022-02-16 : 30
2021-12-12 : 45
2021-11-23 : 60
2020-04-01 : 24
2020-04-01 : 42
see how it's walking backwards through the dates? main character energy, honestly. and note the duplicate April/1/2020 entries β it's a multimap, bestie, duplicates are its whole thing. slay. π₯
π SEE ALSO π
rbeginβ returns a reverse iterator to the beginningcrbeginβ (public member function) (C++11)rendβ returns a reverse end iterator for a container or arraycrendβ (function template) (C++14)
bestie reminder: rend() points past the last element of the reversed view. dereferencing it = undefined behavior = we don't do that here. π«Ά
signing off from cppreference.com, version 2024.06.10 β go forth and reverse-iterate responsibly, love u, mwah π
π¦ 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