Namespaces
Variants
Views
Actions

std::{{{1}}}::shrink_to_fit

From cppreference.com
Revision as of 17:49, 13 August 2023 by Xmcgcg (Talk | contribs)

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.

Contents

Parameters

(none)

Type requirements
-
T must meet the requirements of MoveInsertable.

Return value

(none)

Complexity

At most linear in the size of the container.

Exceptions

If an exception is thrown other than by T's move constructor, there are no effects.

Notes

In libstdc++, shrink_to_fit() is not available in C++98 mode.

Example

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

See also

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