
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
map get_allocator in C++ STL
In this article we will be discussing the working, syntax and examples of map::get_allocator() function in C++ STL.
What is Map in C++ STL?
Maps are the associative container, which facilitates to store the elements formed by a combination on key value and mapped value in a specific order. In a map container the data is internally always sorted with the help of its associated keys. The values in map container is accessed by its unique keys.
What is map::get_allocator()?
The map::get_allocator( ) is a function which comes under <map> header file. get_alloctaor() is used to get the allocator object which is associated with the map container. This function returns the copy of the allocator object of the given map.
Syntax
map_name.get_allocator(key_value k);
Parameters
This function accepts no parameter
Return value
It returns an allocator object of the map.
Example
#include <bits/stdc++.h> using namespace std; int main() { map<int, int> TP; map<int, int>::allocator_type tp = TP.get_allocator(); cout << "checking Is allocator Pair<int, int> : "<< boolalpha << (tp == allocator<pair<int, int> >()); return 0; }
Output
checking Is allocator Pair<int, int> : true
Example
#include <bits/stdc++.h> using namespace std; int main(void) { map<char, int> TP; pair<const char, int>* TP_pair; TP_pair = TP.get_allocator().allocate(5); cout<<"Size after allocating is: " << sizeof(*TP_pair) * 5 << endl; return 0; }
Output
Size after allocating is: 40
- Related Articles
- map::at() and map::swap() in C++ STL
- map equal_range() in C++ STL
- map emplace() in C++ STL
- map value_comp() in C++ STL
- map::clear() in C++ STL
- map insert() in C++ STL
- map operator= in C++ STL
- map::empty() in C++ STL
- map::size() in C++ STL
- map::at() in C++ STL
- map max_size() in C++ STL
- Set vs Map in C++ STL
- map emplace_hint() function in C++ STL
- map erase() function in C++ STL
- map find() function in C++ STL

Advertisements