I was reading the cppreference documentation on vectors erase method. The documentation used the general syntax: it = v.erase(it);
to remove the element it
was pointing to and then increment it
to the next element in the vector.
By accident I noticed that:
std::vector<int> v = {1, 2, 3, 4, 5};
auto it = v.begin();
it = v.erase(it);
std::cout << *it << std::endl; // 2
and
std::vector<int> v = {1, 2, 3, 4, 5};
auto it = v.begin();
v.erase(it);
std::cout << *it << std::endl; // 2
seems to work exactly the same. Is there any difference between the two? If they are the same: why is it = v.erase(it);
the preferred syntax? it = v.erase(it);
seems a little unnecessary if v.erase(it);
does the exact same.