deque get_allocator in C++ STL

deque::get_allocator() is a built in function in C++ STL which is used to get allocator of container deque.
Syntax:

Allocator_type get_allocator()

Parameters: This function does not accept any parameter.
Return value: Returns an allocator associated with deque.

Below programs illustrate the working of deque::get_allocator() function.
Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to illustrate
// deque get_allocator()
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    //'de' is object of 'deque'
    deque<int> de;
  
    //'allocator_type' is inherit in 'deque'
    //'d' is object of 'allocator_type'
    deque<int>::allocator_type d = de.get_allocator();
  
    // Comparing the Allocator with Pair<int, int>
    cout << "Is allocator Pair<int, int> : "
         << boolalpha
         << (d == allocator<pair<int, int> >());
  
    return 0;
}

chevron_right


Output:

Is allocator Pair : true

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to illustrate
// deque get_allocator()
#include <bits/stdc++.h>
using namespace std;
  
int main(void)
{
  
    // Creating a container of type deque
    deque<int> de;
  
    // creating a pointer of type int
    int* array;
  
    // creating array using mylist get_allocator
    array = de.get_allocator().allocate(3);
  
    // inserting some data into array
    for (int i = 0; i < 3; i++)
        array[i] = i;
  
    // printing details of array
    for (int i = 0; i < 3; i++)
        cout << array[i] << " ";
  
    return 0;
}

chevron_right


Output:

0 1 2


My Personal Notes arrow_drop_up

All powers are within you You can do anything and everything Believe in that

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.