名前空間
変種
操作

std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator>::begin, std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator>::cbegin

From cppreference.com
 
 
 
 
iterator begin() noexcept;
(1) (C++11以降)
const_iterator begin() const noexcept;
(2) (C++11以降)
const_iterator cbegin() const noexcept;
(3) (C++11以降)

unordered_multimap の最初の要素へのイテレータを返します。

unordered_multimap が空の場合、返されるイテレータは end() と等しくなります。

range-begin-end.svg

目次

[編集] 戻り値

最初の要素へのイテレータ。

[編集] 計算量

定数。

[編集]

#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';
}

実行結果の例

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

[編集] 関連項目

末尾へのイテレータを返す
(public メンバ関数) [編集]
(C++11)(C++14)
コンテナまたは配列の先頭を指すイテレータを返す
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)