std::multim...timap::cend(3)

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

okay bestie, welcome to std::multim...timap::cend(3) β€” straight from the C++ Standard Libary manual (yes, β€œLibary,” typo intact, it's iconic πŸ’…). this is the group-chat rundown of std::multimap::end and std::multimap::cend, no cap.

✨ NAME ✨

  • std::multimap::end,std::multimap::cend β€” std::multimap::end,std::multimap::cend

🫢 Synopsis 🫢

three overloads, and the noexcept receipts are right here:

          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)

so what's the tea? Returns an iterator to the element following the last element of the multimap.

and then the warning, plain as day: This element acts as a placeholder; attempting to access it results in undefined behavior. that's the β€œdo not touch” zone, bestie πŸ’€. undefined behavior is not a vibe.

the original page also has a diagram asset named range-begin-end.svg; it's giving range-begin-end realness 🌈.

πŸŽ€ Parameters πŸŽ€

(none) β€” literally none, bestie. no parameters, no stress 🫢

πŸ’– Return value πŸ’–

Iterator to the element following the last element. β€” that's the exact return value, periodt.

⚑ Complexity ⚑

Constant. β€” that's it, that's the complexity ✨

πŸ“ Notes πŸ“

libc++ backports cend() to C++98 mode. lowkey a nice little note, periodt.

🌸 Example 🌸

run this code, it's the whole example, character-for-character:

       // 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 πŸ¦‹

Possible output: is exactly this:

        { 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 πŸ‘€

  • begin β€” returns an iterator to the beginning
  • cbegin β€” (public member function); the page also has (C++11) right there
  • end
  • cend β€” returns an iterator to the end of a container or array; the page also has (C++11), (function template), and (C++14) nearby

okay that's the whole page, bestie. it came from http://cppreference.com, dated 2024.06.10, and the footer also spells out std::multim...timap::cend(3). stay hydrated, dereference nothing you don't own, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from