Skip to content
Related Articles

Related Articles

unordered_multimap get_allocator in C++ STL
  • Last Updated : 19 Dec, 2018

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:




// 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;
}
Output:
Is allocator Pair : true

Example-2:




// 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;
}
Output:
Allocated size = 64
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.



My Personal Notes arrow_drop_up
Recommended Articles
Page :