Reading the manual about vector::resize http://www.cplusplus.com/reference/vector/vector/resize/
It only says what happens if the size is greater or smaller, but does not say what happens if it's equal. Is it guaranteed that on equal size it will not reallocate the array and invalidate the iterators?
I wanted to avoid one branch and handle only 2 cases (>= or <) instead of 3 (< or > or ==), but if resizing to same size is undefined, then i will have to check that case too.
This is probably just an error in the linked reference. The standard says following:
void resize(size_type sz);Effects: If
sz < size(), erases the lastsize() - szelements from the sequence. Otherwise, appendssz - size()default-inserted elements to the sequence.
Since sz - size() is 0 in your case, it doesn't do anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With