unordered_map get_allocator in C++ STL
Last Updated :
19 Dec, 2018
unordered_map::get_allocator() is a built in function in C++ STL which is used to get allocator of container unordered_map.
Syntax
Allocator_type get_allocator()
Parameters: This function does not accept any parameter.
Return value: Returns an allocator associated with unordered_map.
Below programs explains clearly the unordered_map::get_allocator() function.
Example-1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map< int , int > ump;
unordered_map< int , int >::allocator_type u = ump.get_allocator();
cout << "Is allocator Pair<int, int> : "
<< boolalpha
<< (u == allocator<pair< int , int > >());
return 0;
}
|
Output:
Is allocator Pair : true
Example-2:
#include <bits/stdc++.h>
using namespace std;
int main( void )
{
unordered_map< char , int > um;
pair< const char , int >* a;
a = um.get_allocator().allocate(8);
cout << "Allocated size = " << sizeof (*a) * 8 << endl;
return 0;
}
|
Output:
Allocated size = 64
Share your thoughts in the comments
Please Login to comment...