unordered_multimap get_allocator in C++ STL

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

Allocator_type get_allocator()

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

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

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to illustrate
// unordered_multimap get_allocator()
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    //'ump' is object of 'unordered_multimap'
    unordered_multimap<int, int> ump;
  
    //'allocator_type' is inherit in 'unordered_multimap'
    //'u' is object of 'allocator_type'
    unordered_multimap<int, int>::allocator_type u = ump.get_allocator();
  
    // Comparing the Allocator with Pair<int, int>
    cout << "Is allocator Pair<int, int> : "
         << boolalpha
         << (u == 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
// unordered_multimap get_allocator()
#include <bits/stdc++.h>
using namespace std;
  
int main(void)
{
    unordered_multimap<char, int> um;
    pair<const char, int>* a;
  
    a = um.get_allocator().allocate(8);
  
    cout << "Allocated size = " << sizeof(*a) * 8 << endl;
  
    return 0;
}

chevron_right


Output:

Allocated size = 64

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.