There's more...
The std::vector allocates bigger chunks of memory if a user inserts an element and it is impossible to fit the new value into the already allocated memory. In that case, std::vector moves elements from the old location to the new one if the elements are nothrow move constructible. Otherwise, std::vector copies elements to a new location and after that calls destructor for each element in the old location.
Because of that, behavior std::vector has amortized constant complexity for many member functions. The static_vector never allocates memory so that it does not have to move or copy elements from an old location to a new one. Because of that, operations that have amortized O(1) complexity for std::vector have true O(1) complexity ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access