English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and examples of Deque shrink_to_fit()

C++ Deque (Double-ended Queue)

C ++ The Dequerink_to_fit() function reduces the container size to the size of the storage space occupied by the elements. This function does not modify the content of the deque.

Syntax

void shrink_to_fit();

Parameters

It does not contain any parameters.

Return value

It does not return any value.

Example1

Let's see a simple example

#include<iostream>
#include<deque>
using namespace std;
int main()
{
 deque<int> d={1,2,3,4,5};
 cout << "size: " << d.size();
 d.resize(3);
 cout << '\n';
 cout << "size:" << d.size();
 d.shrink_to_fit();
 return 0;
}

C++ Deque (Double-ended Queue)