std::multimap::begin,(3)
๐ std::multimap::begin ๐
okay bestie, welcome to the C++ Standard Libary manual page for std::multimap::begin โ yes, the header spells it โLibary,โ and we are keeping the typo energy. The page title is std::multimap::begin,(3), and this is literally the function that hands you an iterator to the first element of a multimap. โจ
Empty multimap? Then the returned iterator will be equal to end(). Thatโs the rule, no cap. ๐
โจ NAME โจ
std::multimap::begin, โ the NAME line is literally std::multimap::begin, - std::multimap::begin, and honestly? Duplicate-comma main character moment. Weโre not fixing it, weโre respecting it. ๐
๐ธ Synopsis ๐ธ
iterator begin(); (1) (noexcept since C++11)
const_iterator begin() const; (2) (noexcept since C++11)
const_iterator cbegin() const noexcept; (3) (since C++11)
Returns an iterator to the first element of the multimap.
If the multimap is empty, the returned iterator will be equal to end().
Thereโs also a diagram reference in the original page: range-begin-end.svg ๐ผ๏ธโจ โ not me inventing lore, itโs literally in there.
๐งธ Parameters
(none) โ literally no parameters. Not a single one, bestie. ๐ซถ
๐ Return value
Iterator to the first element. Thatโs the whole gift. ๐
โก Complexity
Constant. Thatโs it, thatโs the complexity. โก
๐ Notes
libc++ backports cbegin() to C++98 mode. ๐ฐ๏ธโจ ngl, a little time-travel moment.
๐ป Example
Hereโs the example, preserved exactly โ donโt come for me, Iโm not touching the code:
// Run this code
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <map>
#include <string>
int main()
{
auto show_node = [](const auto& node, char ending = '\n')
{
std::cout << "{ " << node.first << ", " << node.second << " }"
<< ending;
};
std::multimap<std::size_t, std::string> mmap;
assert(mmap.begin() == mmap.end()); // OK
assert(mmap.cbegin() == mmap.cend()); // OK
mmap.insert({ sizeof(long), "LONG" });
show_node(*(mmap.cbegin()));
assert(mmap.begin() != mmap.end()); // OK
assert(mmap.cbegin() != mmap.cend()); // OK
mmap.begin()->second = "long";
show_node(*(mmap.cbegin()));
mmap.insert({ sizeof(int), "int" });
show_node(*mmap.cbegin());
mmap.insert({ sizeof(short), "short" });
show_node(*mmap.cbegin());
mmap.insert({ sizeof(char), "char" });
show_node(*mmap.cbegin());
mmap.insert({{ sizeof(float), "float" }, { sizeof(double),
"double"}});
std::cout << "mmap = { ";
std::for_each(mmap.cbegin(), mmap.cend(), [&](const auto& n) {
show_node(n, ' '); });
std::cout << "};\n";
}
๐ฎ Possible output
{ 8, LONG }
{ 8, long }
{ 4, int }
{ 2, short }
{ 1, char }
mmap = { { 1, char } { 2, short } { 4, int } { 4, float } { 8, long } {
8, double } };
๐ See also
endโ returns an iterator to the end.cendโ(public member function),(C++11).beginandcbeginโ returns an iterator to the beginning of a container or array;(C++11),(function template),(C++14).
okay thatโs the page, bestie. Source/version: http://cppreference.com, dated 2024.06.10 โ manual footer was std::multimap::begin,(3) and we are sending it off with a ๐ซถ. Byeee! ๐โจ
๐ฆ 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