Namespaces
Variants
Views
Actions

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 reduce {{#ifeq:{{{1|}}}|vector|{{lc|capacity()}}|{{tt|capacity}}}} to {{lc|size()}}. It depends on the implementation if the request is fulfilled.  
+
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.
{{#ifeq:{{{1|}}}|vector|
 
  
 
===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.

Contents

Parameters

(none)

Type requirements

Template:par req concept

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

See also

returns the number of elements
(public member function of std::{{{1}}}) [edit]