The first issue is your comparison operator is not folowing the strict weak ordering that std::set
requires. You are only comparing L
when you need to check if the L
's are equal and if they are then comapre against r
.
bool operator<(const _point &a)const
{
if (L == a.L)
return r < a.r;
return L < a.L;
}
The second issue you have is that erase()
invalidates the iterators since they point to the location you erased. If you are going to erase like this you will need two other iterators to point to the next item in each set. then after the erase you can assign those pointer back to the ones you just erased.
if((*it_up).L+(*it_down).L!=c1||(*it_up).r+(*it_down).r!=c2||(*it_up).r+(*it_down).L!=d2||(*it_up).L+(*it_down).r!=d1)
{
set<_point>::iterator up_temp = std::next(it_up);
set<_point>::iterator down_temp = std::next(it_down);
up.erase(*it_up);
down.erase(*it_down);
it_up = up_temp;
it_down = down_temp;
}