std::multimap<Key,T,Compare,Allocator>::begin, std::multimap<Key,T,Compare,Allocator>::cbegin
De cppreference.com
iterator begin(); |
(hasta C++11) | |
iterator begin() noexcept; |
(desde C++11) | |
const_iterator begin() const; |
(hasta C++11) | |
const_iterator begin() const noexcept; |
(desde C++11) | |
const_iterator cbegin() const noexcept; |
(desde C++11) | |
Devuelve un iterador al primer elemento del multimap
.
Si el multimap
está vacío, el iterador devuelto será igual a end().
Contenido |
[editar] Parámetros
(Ninguno)
[editar] Valor de retorno
Iterador al primer elemento.
[editar] Complejidad
Constante.
[editar] Ejemplo
Ejecuta este código
#include <algorithm> #include <cassert> #include <iostream> #include <map> #include <string> #include <cstddef> int main() { auto mostrar_nodo = [](const auto& nodo, char final = '\n') { std::cout << "{ " << nodo.first << ", " << nodo.second << " }" << final; }; std::multimap<std::size_t, std::string> mmap; assert(mmap.begin() == mmap.end()); // de acuerdo assert(mmap.cbegin() == mmap.cend()); // de acuerdo mmap.insert({ sizeof(long), "LONG" }); mostrar_nodo(*(mmap.cbegin())); assert(mmap.begin() != mmap.end()); // de acuerdo assert(mmap.cbegin() != mmap.cend()); // de acuerdo mmap.begin()->second = "long"; mostrar_nodo(*(mmap.cbegin())); mmap.insert({ sizeof(int), "int" }); mostrar_nodo(*mmap.cbegin()); mmap.insert({ sizeof(short), "short" }); mostrar_nodo(*mmap.cbegin()); mmap.insert({ sizeof(char), "char" }); mostrar_nodo(*mmap.cbegin()); mmap.insert({{ sizeof(float), "float" }, { sizeof(double), "double" }}); std::cout << "mmap = { "; std::for_each(mmap.cbegin(), mmap.cend(), [&](const auto& n) { mostrar_nodo(n, ' '); }); std::cout << "};\n"; }
Posible salida:
{ 8, LONG } { 8, long } { 4, int } { 2, short } { 1, char } mmap = { { 1, char } { 2, short } { 4, int } { 4, float } { 8, long } { 8, double } };
[editar] Véase también
(C++11) |
Devuelve un iterador al final. (función miembro pública) |