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:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
deque< int > de;
deque< int >::allocator_type d = de.get_allocator();
cout << "Is allocator Pair< int , int > : "
<< boolalpha
<< (d == allocator<pair< int , int > >());
return 0;
}
|
Output:
Is allocator Pair : true
Example-2:
CPP
#include <bits/stdc++.h>
using namespace std;
int main( void )
{
deque< int > de;
int * array;
array = de.get_allocator().allocate(3);
for ( int i = 0; i < 3; i++)
array[i] = i;
for ( int i = 0; i < 3; i++)
cout << array[i] << " ";
return 0;
}
|
Time complexity: O(1).
Auxiliary Space: O(n). // n is the size of the deque.
Last Updated :
20 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...