std::multis...tiset::cend(3)

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

okay bestie, buckle up: this is std::multis...tiset::cend(3) from the C++ Standard Libary manual, and we are gonna make end iterators feel iconic πŸ’–βœ¨

πŸŽ€ NAME πŸŽ€

std::multiset::end,std::multiset::cend - std::multiset::end,std::multiset::cend

that's the name, no cap. end and cend are both living here together.

✨ Synopsis ✨

the signature lineup, exactly:

iterator end();                       (1) (noexcept since C++11)
const_iterator end() const;           (2) (noexcept since C++11)
const_iterator cend() const noexcept; (3) (since C++11)

Returns an iterator to the element following the last element of the multiset.

This element acts as a placeholder; attempting to access it results in undefined behavior.

there's also a diagram placeholder on the page: range-begin-end.svg πŸ¦‹

🌸 Parameters 🌸

(none) β€” literally none, bestie. zero parameters, zero drama.

πŸ¦‹ Return value πŸ¦‹

Iterator to the element following the last element.

πŸ’œ Complexity πŸ’œ

Constant. always and forever.

πŸ‘‘ Notes πŸ‘‘

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 yeah, no sneaky edits through these iterators β€” that's the whole vibe πŸ’…

Also: libc++ backports cend() to C++98 mode. periodt.

πŸ“ Example πŸ“

the page says // Run this code, and then this exact block:

#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: πŸ“

come:   1
not:    1
out:    1
some:   1
sorted: 2
will:   1
words:  1

🌈 See also 🌈

the see-also table is a lil squished in the original, so here's every crumb exactly as it appears:

begin   returns an iterator to the beginning
cbegin  (public member function)
(C++11)
end
cend    returns an iterator to the end of a container or array
(C++11) (function template)
(C++14)

mwah πŸ’‹ that's the whole page β€” source http://cppreference.com, version/date 2024.06.10, page std::multis...tiset::cend(3). byeee πŸ’–

πŸ“¦ where this page comes from