Espacios de nombres
Variantes

std::set<Key,Compare,Allocator>::begin, std::set<Key,Compare,Allocator>::cbegin

De cppreference.com

[edit template]
 
 
 
 
<tbody>
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
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 set.

Si el set está vacío, el iterador devuelto será igual a end().

Parámetros

(Ninguno)

Valor de retorno

Iterador al primer elemento.

Complejidad

Constante.

Notas

Ya que tanto iterator como const_iterator son iteradores constantes (y de hecho pueden ser del mismo tipo), no es posible mutar los elementos del contenedor a través de un iterador devuelto por ninguna de estas funciones miembro.

Ejemplo

#include <algorithm>
#include <iostream>
#include <set>

int main() {
  std::set<int> set = { 3, 1, 4, 1, 5, 9, 2, 6, 5 };
  std::for_each(set.cbegin(), set.cend(), [](int x) {
    std::cout << x << ' ';
  });
  std::cout << '\n';
}

Salida:

1 2 3 4 5 6 9

Véase también

(C++11)
Devuelve un iterador al final.
(función miembro pública) [editar]