std::unordered_set::begin, std::unordered_set::cbegin
Da cppreference.com.
iterator begin() noexcept; |
||
const_iterator begin() const noexcept; |
||
const_iterator cbegin() const noexcept; |
||
Restituisce un iteratore al primo elemento del container.
Se il container è vuoto, l'iteratore restituito sarà uguale a end().
Parametri
(nessuno)
Valore restituito
Iteratore al primo elemento
Complessità
Costante Template:cpp/container/constant iterator note
Example
#include <iostream>
#include <unordered_set>
struct Point { double x, y; };
int main() {
Point pts[3] = { {1, 0}, {2, 0}, {3, 0} };
//points is a set containing the addresses of points
std::unordered_set<Point *> points = { pts, pts + 1, pts + 2 };
//Change each y-coordinate of (i, 0) from 0 into i^2 and print the point
for(auto iter = points.begin(); iter != points.end(); ++iter){
(*iter)->y = ((*iter)->x) * ((*iter)->x); //iter is a pointer-to-Point*
std::cout << "(" << (*iter)->x << ", " << (*iter)->y << ") ";
}
std::cout << '\n';
//Now using the range-based for loop, we increase each y-coordinate by 10
for(Point * i : points) {
i->y += 10;
std::cout << "(" << i->x << ", " << i->y << ") ";
}
}
Possible output:
(3, 9) (1, 1) (2, 4)
(3, 19) (1, 11) (2, 14)
Vedi anche
restituisce un iteratore fino alla fine Original: returns an iterator to the end The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (metodo pubblico) | |