Message from C, C++ discussions
December 2019
— How i think it's a previous pointer before the end
Ok, SO telling that this is ok https://stackoverflow.com/questions/5322104/how-portable-is-end-iterator-decrement
— Unless the list is empty
— auto it = ++it;
I think you increment it
twice per iteration
— Or is it intended like that?
— It's my mistake
— I've changed it but it's not still working auto end = points.end();
--end; --end;
for (auto it = points.begin(); it != end;)
{
auto it2 = ++it;
while (it2 != points.end())
{
if (it->x == it2->x && it->y == it2->y && it->z == it2->z)
it2 = points.erase(it2);
else
++it2;
}
}
— I see one more problem (except that you keep saying "not working" without providing what exactly is going wrong).
Your it and it2 are equal at the start of each iteration. Because you increment it
when set it2
.
You should set it2 = it and then increment it2 only. And increment it
at the and of the iteration (or better in the loop expression, as it was before)
— Ah, hard to explain something with such a variable name in the context :)
— You can convert it to a set and back to a list
— I've finally do it: for (auto it = points.begin(); it != prev(points.end()); it++)
{
auto it2 = next(it);
while (it2 != points.end())
{
if (it->x == it2->x && it->y == it2->y && it->z == it2->z)
it2 = points.erase(it2);
else
++it2;
}
}
— Looks like a very high complexity