list get_allocator in C++ STL
list::get_allocator() is an inbuilt in function in C++ STL which is used to get allocator of container list.
Syntax:
Allocator_type get_allocator()
Parameters: This function does not except any parameter.
Return value: Returns an allocator associated with list.
Below programs explains clearly the list::get_allocator() function.
Example-1:
#include <bits/stdc++.h>
using namespace std;
int main( void )
{
list< int > mylist;
int * array;
array = mylist.get_allocator().allocate(3);
for ( int i = 0; i < 3; i++)
array[i] = i;
for ( int i = 0; i < 3; i++)
cout << array[i] << " " ;
}
|
Example-2:
#include <bits/stdc++.h>
using namespace std;
int main( void )
{
list<string> mylist;
string* array;
array = mylist.get_allocator().allocate(3);
array[0] = "Geeks" ;
array[1] = "For" ;
array[2] = "Geeks" ;
for ( int i = 0; i < 3; i++)
cout << array[i] << " " ;
}
|
Last Updated :
19 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...