I am currently thinking why STL implement vector pop_back in this way. Why we move the finish pointer foreword first and then use finish pointer deallocate the space of last element?
void pop_back() {
--_M_finish;
destroy(_M_finish);
}
Most likely _M_finish
is the end pointer, that is points to the item just after the last item. After pointer has been moved one step back it will point to the current last item that is going to be deleted. And after that item is deleted _M_finish
will continue to point at the same item which is now again is the item just after the last item.
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