Difference between revisions of "Template:cpp/container/shrink to fit"
From cppreference.com
m ("at most" linear is the wording) |
(+) |
||
Line 9: | Line 9: | ||
Requests the removal of unused capacity. | Requests the removal of unused capacity. | ||
− | It is a non-binding request to | + | It is a non-binding request to {{#ifeq:{{{1|}}}|vector|reduce {{lc|capacity()}} to {{lc|size()}}|reduce the memory usage without changing the size of the sequence}}. It depends on the implementation if the request is fulfilled. |
{{cpp/container/note iterator invalidation|{{{1|}}}|shrink_to_fit}} | {{cpp/container/note iterator invalidation|{{{1|}}}|shrink_to_fit}} | ||
Line 26: | Line 26: | ||
===Complexity=== | ===Complexity=== | ||
At most linear in the size of the container. | At most linear in the size of the container. | ||
− | |||
===Notes=== | ===Notes=== | ||
If an exception is thrown other than by T's move constructor, there are no effects. | If an exception is thrown other than by T's move constructor, there are no effects. | ||
− | + | ||
===Example=== | ===Example=== | ||
{{include|cpp/container/{{{1|}}}/example_shrink_to_fit}} | {{include|cpp/container/{{{1|}}}/example_shrink_to_fit}} |
Revision as of 20:52, 16 November 2016
void shrink_to_fit(); |
(since C++11) | |
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 if the request is fulfilled.
Information on iterator invalidation is copied from here |
Contents |
Parameters
(none)
Type requirements |
Return value
(none)
Complexity
At most linear in the size of the container.
Notes
If an exception is thrown other than by T's move constructor, there are no effects.
Example
Templated content. The link is cpp/container/<PP>/example_shrink_to_fit |
See also
returns the number of elements (public member function of std::{{{1}}} )
|