list emplace() function in C++ STL Last Updated : 27 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The list::emplace() is a built-in function in C++ STL which extends list by inserting new element at a given position. Syntax: list_name.emplace(position, element)Parameters: The function accepts two mandatory parameters which are described below: position - it specifies the iterator which points to the position in the list where the new element is to be inserted.args - it specifies the elements to be inserted in the list container.Return value: It returns a random access iterator which points to the newly inserted element. Below programs illustrate the above function: Program 1: CPP // C++ program to illustrate the // list::emplace() function #include <bits/stdc++.h> using namespace std; int main() { // declaration of list list<int> lis = { 5, 6, 7, 8, 9, 10 }; auto it = lis.emplace(lis.begin(), 2); // inserts at the beginning of the list lis.emplace(it, 1); cout << "List: "; for (auto it = lis.begin(); it != lis.end(); ++it) cout << *it << " "; return 0; } OutputList: 1 2 5 6 7 8 9 10 Time Complexity: O(n)Auxiliary Space: O(1) Program 2: CPP // C++ program to illustrate the // list::emplace() function #include <bits/stdc++.h> using namespace std; int main() { // declaration of list list<pair<int, char> > lis; // inserts at the beginning of the list auto it = lis.emplace(lis.begin(), 4, 'a'); // inserts at the beginning of the list lis.emplace(it, 3, 'b'); cout << "List: "; for (auto it : lis) cout << "(" << it.first << ", " << it.second << ") "; return 0; } OutputList: (3, b) (4, a) Time Complexity: O(n)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article list emplace() function in C++ STL T Twinkl Bajaj Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-list +1 More Practice Tags : CPPMiscSTL Similar Reads set emplace_hint() function in C++ STL The set::emplace_hint() is a built-in function in C++ STL which inserts a new element in the set. A position is passed in the parameter of the function which acts as a hint from where the searching operation starts before inserting the element at its current position. The position only helps the pro 2 min read multiset emplace_hint() function in C++ STL The multiset::emplace_hint() is a built-in function in C++ STL which inserts a new element in the multiset. A position is passed in the parameter of the function which acts as a hint from where the searching operation starts before inserting the element at its current position. The position only hel 3 min read map emplace_hint() function in C++ STL The map::emplace_hint() is a built-in function in C++ STL which inserts the key and its element in the map container with a given hint. It effectively increases the container size by one as map is the container that stores keys with the element value. The hint provided does not affect the position t 2 min read 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_n 2 min read unordered_set emplace() function in C++ STL The unordered_set::emplace() function is a built-in function in C++ STL which is used to insert an element in an unordered_set container. The element is inserted only if it is not already present in the container. This insertion also effectively increases the container size 1.Syntax: unordered_set_n 2 min read Like