std::basic_string<CharT,Traits,Allocator>::shrink_to_fit (3) - Linux Manuals
std::basic_string<CharT,Traits,Allocator>::shrink_to_fit: std::basic_string<CharT,Traits,Allocator>::shrink_to_fit
NAME
std::basic_string<CharT,Traits,Allocator>::shrink_to_fit - std::basic_string<CharT,Traits,Allocator>::shrink_to_fit
Synopsis
void shrink_to_fit(); (since C++11)
Requests the removal of unused capacity.
It is a non-binding request to reduce capacity() to size(). It depends on the implementation if the request is fulfilled.
If (and only if) reallocation takes place, all pointers, references, and iterators are invalidated.
Parameters
(none)
Return value
(none)
Complexity
(unspecified) (until C++17)
Linear in the size of the string (since C++17)
Example
// Run this code
Possible output:
See also
size (public member function)
length
capacity (public member function)