multiset get_allocator() function in C++ STL

The multiset::get_allocator() method in C++ STL is a built-in function in C++ STL which returns a copy of the allocator object associated with the multiset.

Syntax:

multiset_name.get_allocator()

where allocator_type is the type of the allocator used by the container.

Parameters: The function does not take any parameter.

Return Value: This method returns the allocator object used to construct the container.

Below programs illustrate the multiset::get_allocator() function:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP code to illustrate multiset::get_allocator
  
#include <iostream>
#include <set>
using namespace std;
  
int main()
{
    multiset<int> mymultiset;
    int* p;
    unsigned int i;
  
    // allocate an array of 5 elements
    // using myset's allocator:
    p = mymultiset
            .get_allocator()
            .allocate(5);
  
    // assign some values to array
    p[0] = 10;
    p[1] = 10;
    p[2] = 20;
    p[3] = 30;
    p[4] = 20;
  
    cout << "The allocated array contains: ";
    for (i = 0; i < 5; i++) {
  
        cout << p[i] << " ";
    }
    cout << endl;
  
    mymultiset.get_allocator().deallocate(p, 5);
  
    return 0;
}

chevron_right


Output:

The allocated array contains: 10 10 20 30 20


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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.