std::unorde...imap::begin,(3)

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

πŸ’– NAME πŸ’–

okay so this is the std::unorde...imap::begin,(3) page from the C++ Standard Libary manual β€” yes, it really says Libary in the header, not my typo, bestie. The NAME line is literally std::unordered_multimap::begin, - std::unordered_multimap::begin, β€” comma chaos included, no cap. We're here for std::unordered_multimap::begin and its iterator besties. πŸ’…

✨ Synopsis ✨

iterator begin() noexcept;              (1) (since C++11)
const_iterator begin() const noexcept;  (2) (since C++11)
const_iterator cbegin() const noexcept; (3) (since C++11)

Three overloads, all since C++11, all doing the "gimme the first element" thing. 🫢

Returns an iterator to the first element of the unordered_multimap.

If the unordered_multimap is empty, the returned iterator will be equal to end().

There's also a diagram asset named range-begin-end.svg β€” it's giving "visual aid" energy. ✨

πŸŽ€ Parameters πŸŽ€

(none) β€” not a single parameter. Nada. The void. πŸ’€

πŸ¦‹ Return value πŸ¦‹

Iterator to the first element. That's the whole tea. β˜•

🌸 Complexity 🌸

Constant.

πŸ”₯ Example πŸ”₯

okay so here's the code, untouched, because we do not edit code in this house πŸ’…

// Run this code

#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <utility>
#include <unordered_map>

int main()
{
    auto show_node = [](const std::pair<std::string, std::string>& node)
    {
        std::cout << node.first << " : " << node.second << '\n';
    };

    std::unordered_multimap<std::string, std::string> lemmas;
    assert(lemmas.begin() == lemmas.end());
    assert(lemmas.cbegin() == lemmas.cend());

    lemmas.insert({ "1. βˆ€x ∈ N βˆƒy ∈ N", "x ≀ y" });
    show_node(*lemmas.cbegin());
    assert(lemmas.begin() != lemmas.end());
    assert(lemmas.cbegin() != lemmas.cend());

    lemmas.begin()->second = "x < y";
    show_node(*lemmas.cbegin());

    lemmas.insert({ "2. βˆ€x, y ∈ N    ", "x = y V x β‰  y" });
    show_node(*lemmas.cbegin());

    lemmas.insert({ "3. βˆ€x ∈ N βˆƒy ∈ N", "y = x + 1" });
    show_node(*lemmas.cbegin());

    std::cout << "Lemmas: \n";
    std::for_each(lemmas.cbegin(), lemmas.cend(), [&](const auto& n)
    {
        show_node(n);
    });
    std::cout << '\n';
}

🌈 Possible output 🌈

Possible output, exactly as the page lists it:

1. βˆ€x ∈ N βˆƒy ∈ N : x ≀ y
1. βˆ€x ∈ N βˆƒy ∈ N : x < y
2. βˆ€x, y ∈ N     : x = y V x β‰  y
3. βˆ€x ∈ N βˆƒy ∈ N : y = x + 1
Lemmas:
3. βˆ€x ∈ N βˆƒy ∈ N : y = x + 1
1. βˆ€x ∈ N βˆƒy ∈ N : x < y
2. βˆ€x, y ∈ N     : x = y V x β‰  y

πŸ‘€ See also πŸ‘€

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

okay bye bestie 🫢 this page came from http://cppreference.com, dated 2024.06.10, and the footer says std::unorde...imap::begin,(3). slay, periodt. πŸ’–

πŸ“¦ where this page comes from