std::unordered_multimap::begin, std::unordered_multimap::cbegin
Материал из cppreference.com
iterator begin() noexcept; |
(начиная с C++11) | |
const_iterator begin() const noexcept; |
(начиная с C++11) | |
const_iterator cbegin() const noexcept; |
(начиная с C++11) | |
Возвращает итератор на первый элемент unordered_multimap.
Если unordered_multimap - пуст, возвращаемый итератор будет равен end()
Параметры
(нет)
Возвращаемое значение
Итератор на первый элемент.
Сложность
Константная.
Example
Запустить этот код
#include <unordered_map>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <string>
#include <utility>
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()); // OK
assert(lemmas.cbegin() == lemmas.cend()); // OK
lemmas.insert({ "1. ∀x ∈ N ∃y ∈ N", "x ≤ y" });
show_node(*lemmas.cbegin());
assert(lemmas.begin() != lemmas.end()); // OK
assert(lemmas.cbegin() != lemmas.cend()); // OK
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";
}
Возможный вывод:
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
(C++11) |
возвращает итератор на конец (public функция-элемент) |