Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does vector::erase reduce vector::capacity?

Cppreference only says:

Removes specified elements from the container. 1) Removes the element at pos. 2) Removes the elements in the range [first; last).

Invalidates iterators and references at or after the point of the erase, including the end() iterator.

The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.

The iterator first does not need to be dereferenceable if first==last: erasing an empty range is a no-op.

like image 352
themagicalyang Avatar asked Nov 29 '22 21:11

themagicalyang


1 Answers

Not necessarily no. When reading the C++ standard (and cppreference proxies the standard remarkably well), if something is not explicitly mentioned, then assume such a something is not required.

It would possibly be sub-optimal for a C++ Standard Library implementation to do so.

like image 199
Bathsheba Avatar answered Dec 04 '22 13:12

Bathsheba