When working with the HalfedgeMesh class, you will encounter the following, predefined iterators: VertexIter, EdgeIter, FaceIter, and HalfedgeIter.

Instead of detailing exactly what an iterator is, we will discuss with examples how to use an iterator so that you can get started on Assignment 2 quickly.

In most cases, you can treat iterators just like pointers. For example, you can use an iterator HalfedgeIter as a pointer Halfedge *; and dereference the iterator using *Halfedge to get a variable of class Halfedge.

You can check if two iterators refer to the same object using the == operator, exactly the same way you would with pointers.

HalfedgeIter halfedge_a;
HalfedgeIter halfedge_b;
if (halfedge_a == halfedge_b) {
    // They refer to the same half-edge

You can also assign an iterator to another iterator using the = operator.

// v0 and v1 are of class Vertex
// Vertex::halfedge() returns a *reference* to the half-edge at the vertex
// Here we set the half-edge of vertex v0 to be the half-edge of vertex v1
HalfedgeIter halfedge = v0->halfedge();
v1->halfedge() = halfedge;

In addition to behaving like a pointer, an iterator can be used to loop over a list.

// Here we loop over all half-edges of a mesh
for (HalfedgeIter iter = mesh.halfedgesBegin(); iter != mesh.halfedgesEnd(); iter++) {
    *iter; // Here we simply derefernece the iterator
    cout << iter->vertex()->position << endl; // Find out what this does

Note that we use the ++ operator on an iterator to advance it, as if it were an integer index. In contrast, we cannot not use ++ on pointers.

VertexCIter, EdgeCIter, FaceCIter and HalfedgeCIter are the const (i.e., constant) counterparts of the iterators mentioned at the beginning. The fact they are constant just means that the values they point to cannot be modified.

If you are interested in learning what an iterator really is, you are welcome to look into the C++ Standard Template Library (STL) for more information. We recommend that you start here and here.