unordered_multiset emplace() function in C++ STL
The unordered_multiset::emplace() is a built-in function in C++ STL which inserts a new element in the unordered_multiset container. The insertion is done automatically at the position according to the container’s criterion. It increases the size of the container by one.
Syntax:
unordered_multiset_name.emplace(val)
Parameters: The function accepts a single mandatory parameter val which is to be inserted in the container.
Return Value: It returns an iterator which points to the newly inserted element.
Below programs illustrates the above function:
Program 1:
// C++ program to illustrate the // unordered_multiset::emplace() function #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multiset<int> sample; // inserts element using emplace() sample.emplace(11); sample.emplace(11); sample.emplace(11); sample.emplace(12); sample.emplace(13); sample.emplace(13); sample.emplace(14); cout << "Elements: "; for (auto it = sample.begin(); it != sample.end(); it++) cout << *it << " "; return 0; } |
Elements: 14 11 11 11 12 13 13
Program 2:
// C++ program to illustrate the // unordered_multiset::emplace() function #include <bits/stdc++.h> using namespace std; int main() { // declaration unordered_multiset<char> sample; // inserts element using emplace() sample.emplace('a'); sample.emplace('a'); sample.emplace('a'); sample.emplace('b'); sample.emplace('b'); sample.emplace('c'); sample.emplace('d'); cout << "Elements: "; for (auto it = sample.begin(); it != sample.end(); it++) cout << *it << " "; return 0; } |
Elements: d a a a b b c
Recommended Posts:
- unordered_set emplace() function in C++ STL
- vector emplace() function in C++ STL
- list emplace() function in C++ STL
- unordered_multimap emplace() function in C++ STL
- map emplace() in C++ STL
- set::emplace() in C++ STL
- multiset::emplace() in C++ STL
- priority_queue emplace() in C++ STL
- multimap::emplace() in C++ STL
- queue::emplace() in C++ STL
- stack emplace() in C++ STL
- emplace vs insert in C++ STL
- unordered_map emplace() in C++ STL
- deque emplace in C++ STL
- Inserting elements in std::map (insert, emplace and operator [])
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.



