C++ STL unordered_set get_allocator() with Examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The get_allocator() method of unordered_set is the part of Standard Template Library(STL) of C++. This method gets the stored allocator object and returns it. Syntax: allocator_type get_allocator() const; where Allocator_type is the type of allocator used by the container. Return Value: It returns the allocator object used to construct the container. Exceptions: In this method, an Exception is thrown if any element comparison object throws an exception. The below program illustrates the unordered_set::get_allocator() function Program 1: C++ // C++ program to demonstrate // unordered_set get_allocator() #include <iostream> #include <unordered_set> // Their Library using namespace std; int main() { //'c' is object of 'unordered_set' unordered_set<int> c; //'allocator_type' is inherit in 'unordered_set' //'a' is object of 'allocator_type' //'get_allocator()' is member of 'unordered_set' unordered_set<int>::allocator_type a = c.get_allocator(); // Comparing the Allocator with Pair<int, int> cout << "Is allocator Pair<int, int> : " << boolalpha << (a == allocator<pair<int, int> >()); return 0; } OutputIs allocator Pair<int, int> : true Complexity: It takes constant(O(1)) time of complexity to perform an operation. Program 2 : C++ // C++ program to demonstrate // unordered_set get_allocator() #include <iostream> #include <unordered_map> // Their Library 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; } OutputAllocated size = 64 Comment More infoAdvertise with us Next Article unordered_map get_allocator in C++ STL S SoumikMondal Follow Improve Article Tags : C++ STL CPP-Library cpp-containers-library Practice Tags : CPPSTL Similar Reads std::allocator() in C++ with Examples Allocators are objects responsible for encapsulating memory management. std::allocator is used when you want to separate allocation and do construction in two steps. It is also used when separate destruction and deallocation is done in two steps. All the STL containers in C++ have a type parameter A 3 min read unordered_multiset get_allocator in C++ STL The unordered_multiset::get_allocator() function is a STL function in C++ which is used to include unorder_multiset header file in program. This function gets the stored allocator object and returns the allocator object which is used to construct the container. It is a public member function. Syntax 1 min read unordered set of tuples in C++ with Examples What is a tuple? A tuple in C++ is an object which is used to group elements together. In a tuple, elements can be of the same data type or different data types. The elements of tuples are initialized as in the order in which they will be accessed. Functions associated with a tuple: 1. make_tuple(): 6 min read unordered_map get_allocator in C++ STL 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 1 min read 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. 1 min read unordered set of Pairs in C++ with Examples What is pair? Utility header in C++ provides us pair container. A pair consists of two data elements or objects. The first element is referenced as âfirstâ and the second element as âsecondâ and the order is fixed (first, second).Pair is used to combine together two values that may be different in t 5 min read Like