Is code in Method 1 incorrect (using ternary operator). Does ++it has undefined evaluation order here. Or both methods are same:
Method 1:
struct X
{
int id;
int j;
};
void delete_data_from_map(map<int,X>& my_map, int const id)
{
for(auto it {my_map.begin()}; it != my_map.end();)
{
it = (it->second.id == id) ? my_map.erase(it) : ++it;
}
}
Method 2:
void delete_data_from_map(map<int,X>& my_map, int const id)
{
for(auto it {my_map.begin()}; it != my_map.end();)
{
if(it->second.id == id)
it = my_map.erase(it);
else ++it;
}
}