I'm looping my array to associate some data with another one. If the data doesn't exist, I'm removing the row. Basically if array1[i].frame != array2[i].frame
(the arrays contains structure).
I did that :
struct Sarray1 {int frame; /*...*/; Sarray2 sarray2};
struct Sarray2 {int frame; /*...*/;};
std::vector array1<Sarray1>;
std::vector array2<Sarray2>;
int i = 0;
for (auto& e : array1)
{
if (i >= array2.size())
break;
if (e.frame == array2[i].frame)
e.sarray2= array2[i];
else
array1.erase(array1.begin() + i);
i++;
}
Is it ok to do that way, for deleting the data? I always read that's not good to delete during a loop. Will I have some strange comportement? In don't know about the robustness of foreach
loop in C++ when the size is changing.
Thanks in advance.