B
BCC
I have two vectors of objects, and these objects contain a double,
'ref_mass'. I want to remove the elements in one list from the other. My
erase seems to work okay, except that after erasing the objects
(successfully), my 'clean' vector is still the same length as the original.
And if the vector had a length of 100, and I erase 10, the last 10 elements
(91-100) are just copies of the last real element.
What am I doing wrong?
Thanks,
Bryan
if (remove_list.size() > 0) {
// Copy the list
clean_list = orig_list;
for (ref_it = clean_list.begin(); ref_it != clean_list.end() {
bool b_erase = false;
for (cmp_it = remove_list.begin(); cmp_it != remove_list.end();
++cmp_it) {
if ((*ref_it).ref_mass == (*cmp_it).ref_mass) {
b_erase = true;
break;
}
}
if (b_erase) {
ref_it = clean_list.erase(ref_it);
}
else {
++ref_it;
}
}
}
'ref_mass'. I want to remove the elements in one list from the other. My
erase seems to work okay, except that after erasing the objects
(successfully), my 'clean' vector is still the same length as the original.
And if the vector had a length of 100, and I erase 10, the last 10 elements
(91-100) are just copies of the last real element.
What am I doing wrong?
Thanks,
Bryan
if (remove_list.size() > 0) {
// Copy the list
clean_list = orig_list;
for (ref_it = clean_list.begin(); ref_it != clean_list.end() {
bool b_erase = false;
for (cmp_it = remove_list.begin(); cmp_it != remove_list.end();
++cmp_it) {
if ((*ref_it).ref_mass == (*cmp_it).ref_mass) {
b_erase = true;
break;
}
}
if (b_erase) {
ref_it = clean_list.erase(ref_it);
}
else {
++ref_it;
}
}
}