Пространства имён
Варианты
Действия

std::multimap::begin, std::multimap::cbegin

Материал из cppreference.com
< cpp‎ | container‎ | multimap
 
 
 
 
iterator begin();
(до C++11)
iterator begin() noexcept;
(начиная с C++11)
const_iterator begin() const;
(до C++11)
const_iterator begin() const noexcept;
(начиная с C++11)
const_iterator cbegin() const noexcept;
(начиная с C++11)

Возвращает итератор на первый элемент multimap.

Если multimap - пуст, возвращаемый итератор будет равен end()

range-begin-end.svg

Содержание

[править] Параметры

(нет)

[править] Возвращаемое значение

Итератор на первый элемент.

[править] Сложность

Константная.


[править] Example

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <string>
#include <cstddef>
 
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";
}

Возможный вывод:

{ 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

(C++11)
возвращает итератор на конец
(public функция-элемент) [править]