jeudi 24 septembre 2015

Updating stored indices after erasing an element from std::vector

Suppose that I have a vector of points:

vector<int> points;

Triangles store the indices of points they are made of:

struct Triangle {
    int p0, p1, p2;
};

Triangle tri0;
tri0.p0 = 3;
tri0.p1 = 6;
tri0.p2 = 7;

Triangle tri1;
tri1.p0 = 4;
tri1.p1 = 6;
tri1.p2 = 7;

Now I decide to erase point[3]. However, if I erase the point[3], the indices of points after index 3 will shift back so I need to notify all triangles that the indices they store might be changed. What could be a plausible way of notifying triangles?

Aucun commentaire:

Enregistrer un commentaire