std::multis...set::cbegin(3)
Hey bestie π you're on the std::multis...set::cbegin(3) page from the C++ Standard Libary manual β yes, that's exactly how the manual name is spelled here, no cap. This page is all about std::multiset::begin and std::multiset::cbegin, and it's lowkey iconic.
π NAME π
std::multiset::begin,std::multiset::cbegin - std::multiset::begin,std::multiset::cbegin
That's the whole name block β exact function names, exact comma situation, we're not touching it.
β¨ Synopsis β¨
Here are the three signatures, verbatim, with their numbered tags and noexcept notes:
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)
So what does it do? Returns an iterator to the first element of the multiset. If the multiset is empty, the returned iterator will be equal to end().
There's also a diagram called range-begin-end.svg in the original β imagine it pointing at the beginning and the end like a little visual vibe check. π¦
π«Ά Parameters π«Ά
(none) β literally none. No arguments, no hidden extras, just vibes.
π Return value π
An Iterator to the first element. That's the whole return value. Slay.
β‘ Complexity β‘
Constant. Periodt.
π§ Notes π§
Okay important caveat, bestie: because both iterator and const_iterator are constant iterators (and may in fact be the same type), it is not possible to mutate the elements of the container through an iterator returned by any of these member functions. So don't try to sneak a change in through begin() or cbegin() β not happening. π
Also: libc++ backports cbegin() to C++98 mode.
π Example π
Run this code β it's giving std::multiset<std::string> realness and shows off the duplicate-key situation:
#include <iostream>
#include <iterator>
#include <set>
#include <string>
int main()
{
const std::multiset<std::string> words =
{
"some", "not", "sorted", "words",
"will", "come", "out", "sorted",
};
for (auto it = words.begin(); it != words.end(); )
{
auto count = words.count(*it);
std::cout << *it << ":\t" << count << '\n';
std::advance(it, count); // all count elements have equivalent keys
}
}
π Output π
Output is giving alphabetical-with-a-duplicate realness:
come: 1
not: 1
out: 1
some: 1
sorted: 2
will: 1
words: 1
π See also π
endβ returns an iterator to the endcendβ (public member function) (C++11)begin,cbeginβ returns an iterator to the beginning of a container or array (C++11) (function template) (C++14)
Source/version/date sign-off, because the footer deserves love too: this page is from http://cppreference.com, dated 2024.06.10, and its page tag is std::multis...set::cbegin(3). Bye bestie, go 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