std::{{{1}}}::shrink_to_fit
From cppreference.com
void shrink_to_fit();
|
||
Requests the removal of unused capacity.
It is a non-binding request to reduce the memory usage without changing the size of the sequence. It depends on the implementation whether the request is fulfilled.
| Information on iterator invalidation is copied from here |
|
If |
(since C++11) |
Complexity
At most linear in the size of the container.
ExceptionsIf an exception is thrown other than by the move constructor of a non-CopyInsertable |
(since C++11) |
Notes
In libstdc++, shrink_to_fit() is not available in C++98 mode.
Example
| Templated content. The link is cpp/container/<PP>/example_shrink_to_fit |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 850 | C++98 | std:: lacked explicit shrink-to-fit operations
|
provided |
| LWG 2033 | C++98 C++11 |
1. the complexity requirement was missing (C++98) 2. T was not required to be MoveInsertable (C++11)
|
1. added 2. required |
| LWG 2223 | C++98 C++11 |
1. references, pointers, and iterators were not invalidated (C++98) 2. there was no exception safety guarantee (C++11) |
1. they may be invalidated 2. added |
See also
| returns the number of elements (public member function of std::{{{1}}})
|