Hi, I already posted this same question on StackOverflow, since I have not gotten an answer yet reposting it here too.

Suppose I am iterating over a boost::multi_index using one of the two indices. Then if I start iterating using the other index and erasing an element according some criteria, does that invalidate the upper iterator?

E.g.,

struct person {
    string name;
    string last_name;
    string age;
}

typedef multi_index<
    person,
    index_by<
        ordered_non_unique<person, string, &person::name>,
        ordered_non_unique<person, string, &person::age>
    >
> PersonCollection;

PersonCollection pc;

//insert some elements into pc

auto index0 = pc.get<0>();
auto range0 = index0.equal_range("John");
while (range0.first != range0.second) {
    auto index1 = pc.get<1>();
    auto range1 = index1.equal_range(34);
    while (range1.first != range1.second) {
        if (range1.first->last_name == "Smith")
             range1.first = index1.erase(range1.first);
        else
             ++range1.first;    
    }
    ++range0.first;
}

So in this case, is the range0 iterator always valid? Thanks!


Hovnatan